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

边栏推荐
- Codeforces Round #803 (Div. 2)A~C
- 浏览器打印边距,默认/无边距,占满1页A4
- C language is the watershed between low-level and high-level
- window11 conda安装pytorch过程中遇到的一些问题
- pytorch提取骨架(可微)
- Codeforces Round #799 (Div. 4)A~H
- Write web games in C language
- TCP's three handshakes and four waves
- Luogu P1102 A-B number pair (dichotomy, map, double pointer)
- Candy delivery (Mathematics)
猜你喜欢

Codeforces Round #797 (Div. 3)无F

QT实现圆角窗口

QT style settings of qcobobox controls (rounded corners, drop-down boxes, up expansion, editable, internal layout, etc.)

Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines

QT有关QCobobox控件的样式设置(圆角、下拉框,向上展开、可编辑、内部布局等)

409. Longest palindrome

Candy delivery (Mathematics)

Luogu P1102 A-B number pair (dichotomy, map, double pointer)

Li Kou: the 81st biweekly match

It is forbidden to trigger onchange in antd upload beforeupload
随机推荐
QWidget代码设置样式表探讨
日期加1天
Socket communication
Problem - 922D、Robot Vacuum Cleaner - Codeforces
Summary of FTP function implemented by qnetworkaccessmanager
1605. Sum the feasible matrix for a given row and column
Find 3-friendly Integers
图图的学习笔记-进程
Penetration test 2 --- XSS, CSRF, file upload, file inclusion, deserialization vulnerability
The "sneaky" new asteroid will pass the earth safely this week: how to watch it
力扣——第298场周赛
Kubernetes集群部署
QNetworkAccessManager实现ftp功能总结
969. Pancake sorting
Programmers, what are your skills in code writing?
Click QT button to switch qlineedit focus (including code)
Raspberry pie csi/usb camera uses mjpg to realize web camera monitoring
Read and save zarr files
去掉input聚焦时的边框
Advancedinstaller安装包自定义操作打开文件