当前位置:网站首页>js封装数组反转的方法--冯浩的博客
js封装数组反转的方法--冯浩的博客
2022-07-06 09:29:00 【冯浩(grow up)】
思路:我们使用两个循环 分别遍历出前一个元素和后一个元素,
然后定义一个空的变量,进行位置调换
function reversal(arr){
for(var i =0 ;i<arr.length;i++){
for(var j =i+1;j<arr.length;j++){
var temp ;
temp = arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
var arr = ["a","b","c","d"];
console.log(arr);
reversal(arr);
console.log(arr);

边栏推荐
- Anaconda下安装Jupyter notebook
- QT有关QCobobox控件的样式设置(圆角、下拉框,向上展开、可编辑、内部布局等)
- Understand what is a programming language in a popular way
- Sword finger offer II 019 Delete at most one character to get a palindrome
- window11 conda安装pytorch过程中遇到的一些问题
- Maximum product (greedy)
- VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
- AcWing:第56场周赛
- Auto. Getting started with JS
- 树莓派4B64位系统安装miniconda(折腾了几天终于解决)
猜你喜欢

Share an example of running dash application in raspberry pie.

409. Longest palindrome

Borg maze (bfs+ minimum spanning tree) (problem solving report)

浏览器打印边距,默认/无边距,占满1页A4

Oneforall installation and use

Discussion on QWidget code setting style sheet

拉取分支失败,fatal: ‘origin/xxx‘ is not a commit and a branch ‘xxx‘ cannot be created from it

QT模拟鼠标事件,实现点击双击移动拖拽等

1529. Minimum number of suffix flips

Openwrt source code generation image
随机推荐
2078. Two houses with different colors and the farthest distance
Problem - 1646C. Factorials and Powers of Two - Codeforces
树莓派4B64位系统安装miniconda(折腾了几天终于解决)
Codeforces - 1526C1&&C2 - Potions
Share an example of running dash application in raspberry pie.
Vs2019 initial use
QT实现圆角窗口
QT realizes window topping, topping state switching, and multi window topping priority relationship
(POJ - 3258) River hopper (two points)
Borg maze (bfs+ minimum spanning tree) (problem solving report)
7-1 understand everything (20 points)
Advancedinstaller安装包自定义操作打开文件
HDU - 6024 building shops (girls' competition)
Codeforces Round #798 (Div. 2)A~D
C language is the watershed between low-level and high-level
QNetworkAccessManager实现ftp功能总结
Problem - 922D、Robot Vacuum Cleaner - Codeforces
pytorch提取骨架(可微)
树莓派4B安装opencv3.4.0
Codeforces Round #803 (Div. 2)A~C