翻转数组
var arr2 = [9,5,4,3,2,1]
var c=[]
for(var h = arr2.length-1;h>=0;h--){
c[c.length] = arr2[h]
}
console.log(c)
数组指定元素去重
var arr1 = [2,0,6,1,77,0,52,0,25,7]
var b = []
for(var j = 0;j<arr1.length;j++){
if(arr1[j] != 0){
b[b.length] = arr1[j]
}
}
console.log(b)
冒泡排序
var newArr = [4,5,8,9,6,3,2,0]
var temp = 0
for(var i = 0;i<newArr.length;i++){
for(var j = 0;j<newArr.length-1;j++){
if(newArr[j]>newArr[j+1]){
temp = newArr[j]
newArr[j] = newArr[j+1]
newArr[j+1]= temp
}
}
}
console.log(newArr)
js基础-数组
最新推荐文章于 2024-08-25 09:57:22 发布