var items = [1,2,3,4,5];
//item代表数组的单个元素,index代表索引,arr代表源数组
items.forEach(function(item,index,arr) {
console.log(index + ":" + item + "->" + arr);
})
//输出
// 0:1->1,2,3,4,5
// 1:2->1,2,3,4,5
// 2:3->1,2,3,4,5
// 3:4->1,2,3,4,5
// 4:5->1,2,3,4,5
es6学习_数组方法_forEach
最新推荐文章于 2022-12-29 15:52:05 发布