图片
常用的数组 API
forEach 遍历所有元素,item 对应的是元素的值,index 对应的是元素的位置
let arr = [4, 6, 8];
arr.forEach(function(item...纯函数有两个特点:1....不改变原数组(没有副作用);2....返回一个数组
除了上面提到的 forEach, every, some, filter 属于非纯函数外,我们常用的 push, pop, shift, unshift 方法也属于非纯函数
const arr...console.log(pushRes, arr) // 3 [ 20, 30, 50 ]
console.log(unshiftRes, arr) // 4 [ 5, 20, 30, 50 ]
常用的数组纯函数除了