forEach()方法
知有
214
forEach()方法
forEach()方法能够用于调用数组的每个元素,并将元素传递给回调函数。
语法:
array.forEach(function(currentValue,index,arr),thisValue)
这里的参数:
currentValue:必选,当前的元素。
index:可选,当前元素的索引值。
arr:可选,当前元素所属的数组对象。
thisValue:可选,传递给函数的值一般用"this"值。如果为空,"undefined"会传递给"this"值。
forEach()对空数组是不会执行回调函数的,它是不支持continue与break的。