过滤器高阶函数解释



新来的,有人能帮我详细说明一下吗?我一直在试图理解为什么不"新"。在返回或控制台日志中弹出

let words = ['spray', 'limit', 'exuberant', 'destruction', 'elite', 'present']
const appendedWords = words.filter( (word, index , arr) => {
arr.push('new')
return word.length < 7
})
console.log(appendedWords)

的过滤方法运行所有您提供的数组元素对一个函数,如果他们符合标准。然后它将创建一个新数组并存储该元素。.filter()不修改原始数组,它被认为是不可变.

你只能读取原始数组的值,但不能修改它。

最新更新