1.map和filter函数的参数,是完全相同的
array.map(function(currentValue,index,arr), thisValue)
array.filter(function(currentValue,index,arr), thisValue)
currentValue:数组元素;
index:索引
arr:原数组;
thisValue:作为该执行回调时使用,传递给函数,用作 "this" 的值
2.forEach的参数
array.forEach(function(currentValue,index,arr))
currentValue:数组元素
index:索引
arr:原数组
3.用途
map方法返回的新数组是原数组的映射,何为映射?就是和原数组的长度相同,数值做相应处理。
filter方法返回的值是过滤原数组后的新数组,和原数组长度不同,数值不变。
forEach()常用于遍历数组,用于调用数组的每一个元素,并将其传递给回调函数。传输函数不需要返回值。