//for...in
var arr=[0,1,2,3];
for(var i in arr){
console.log(arr[i]);
}
//for
var arr=[0,1,2,3];
for(var i=0;i<arr.length;i++){
console.log(arr[i]);
}
//forEach
let arr=[0,1,2,3];
arr.forEach((element,index)=>{
console.log(element);
});
//for...of
var arr=[0,1,2,3];
for(var n of arr){
//if(n>arr.length)
//break;
console.log(n);
}
遍历数组的几种方法
最新推荐文章于 2024-11-14 10:56:19 发布