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會繼續更新的~~