forEach() 方法对数组的每个元素执行一次提供的函数。
示例1:
var array1 = ['a', 'b', 'c'];
array1.forEach(function(element) {
console.log(element);
});
// expected output: "a"
// expected output: "b"
// expected output: "c"
示例2:
var array = ['a', 'b', 'c'];
array.forEach(function(currentValue,index,arr){
console.log(currentValue);
});
//a
//b
//c
语法:
arr.forEach(callback[, thisArg]);
参数:
callback,必选,为数组中每个元素执行的函数,该函数接收三个参数:
currentValue
数组中正在处理的当前元素。
index可选
数组中正在处理的当前元素的索引。
array可选
forEach() 方法正在操作的数组。
thisArg,可选参数。当执行回调函数时用作 this 的值(参考对象)。
参考:
最新评论
怎么获取下载密码不对啊?
你给钱了吗在这叫
夸克和百度给了你钱吧?这么多不限速的网盘不用,限速限的一坨屎一样的网盘拼命推荐
博主能不能回复一下具体什么时候更新新版,我怕到时候强制更新就用不了