JS的數組循環遍歷輸出


 

var  arr=[1,2,3,4,5,6,7,8,2,3,4,5]

循環遍歷

已知以上數組為全篇文章通用的數組

1.for循環輸出數組

for(var i=0;i<arr.length;i++){
var cov=arr[i];
console.log(cov);
}

2.for  in方法輸出數組

for(let index in arr){
console.log(index,arr[index])
}

3.forEach方法輸出數組

  

arr.forEach(function(e){
console.log(e)
})

4.for of 方法輸出數組和字符串

for(let v of arr){
console.log(v)
}
let s="hello 95yb"
for(let c of s){
console.log(c);
}

5.map方法輸出數組

arr.map(function(e,i,array){
console.log(e);
return parseTnt(e,10)
})

6.filter方法輸出數組

var r = array.filter(function(x){
return x
})
console.log(r)

  

  用法,95會繼續更新的~~

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM