当前位置:网站首页>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);

边栏推荐
- C language is the watershed between low-level and high-level
- Candy delivery (Mathematics)
- 1689. Ten - the minimum number of binary numbers
- Acwing - game 55 of the week
- Educational Codeforces Round 130 (Rated for Div. 2)A~C
- Generate random password / verification code
- Flag framework configures loguru logstore
- QNetworkAccessManager实现ftp功能总结
- Codeforces Round #802(Div. 2)A~D
- 875. Leetcode, a banana lover
猜你喜欢

It is forbidden to trigger onchange in antd upload beforeupload

Remove the border when input is focused

860. Lemonade change

Local visualization tools are connected to redis of Alibaba cloud CentOS server

QT implementation window gradually disappears qpropertyanimation+ progress bar

Vs2019 initial use

B - Code Party (girls' competition)

Read and save zarr files

树莓派4B64位系统安装miniconda(折腾了几天终于解决)

QT有关QCobobox控件的样式设置(圆角、下拉框,向上展开、可编辑、内部布局等)
随机推荐
Auto. Getting started with JS
Acwing: the 56th weekly match
QT有关QCobobox控件的样式设置(圆角、下拉框,向上展开、可编辑、内部布局等)
QT implementation fillet window
Codeforces Round #800 (Div. 2)AC
Useeffect, triggered when function components are mounted and unloaded
本地可视化工具连接阿里云centOS服务器的redis
Quick to typescript Guide
Pyside6 signal, slot
Anaconda下安装Jupyter notebook
Study notes of Tutu - process
QT style settings of qcobobox controls (rounded corners, drop-down boxes, up expansion, editable, internal layout, etc.)
Sanic异步框架真的这么强吗?实践中找真理
Codeforces Round #801 (Div. 2)A~C
Truck History
Classic application of stack -- bracket matching problem
Write web games in C language
Generate random password / verification code
Interesting drink
(POJ - 2739) sum of constructive prime numbers (ruler or two points)