2025年02月09日 建站教程
es6遍历数组的用法有哪些?下面web建站小编给大家详细介绍一下具体实现代码!
forEach的用法
var arr= ['a', 'b', 'c']; arr.forEach((v,l,k) => { console.log(v); console.log(l); console.log(k); }) //3 a //4 0 //5 (3) ['a', 'b', 'c'] //3 b //4 1 //5 (3) ['a', 'b', 'c'] //3 c //4 2 //5 (3) ['a', 'b', 'c']
for(let k in arr){}的用法
var arr= ['a', 'b', 'c']; for(let k in arr){ console.log(k,arr[k]) } //0 a //1 b //2 c
map()的用法
var a1 = ['a', 'b', 'c']; var a2 = a1.map(function(item,key,ary) { return item.toUpperCase(); }); console.log(a1);// ['a','b','c']; console.log(a2); //['A','B','C'];
本文链接:http://so.lmcjl.com/news/22817/