js数组遍历的几种方式
var team = ['zhangsan','lisi','wagnwu']; //遍历数组方式1 - for循环 for(var i=0;i<team.length;i++){ console.log(team[i]); }; //遍历数组方式2 - 索引遍历 for(var i in team){ console.log(team[i]); }; //遍历数组方式3 - 数组对象.forEach方法 team.forEach(function(v,k){ console.log(v,k); }); team.forEach( function(v) { console.log(v); }); //遍历数组方式4 - for of 值遍历(ES6) for(var v of team){ console.log(v); }

浙公网安备 33010602011771号