新来的,有人能帮我详细说明一下吗?我一直在试图理解为什么返回或控制台日志中没有弹出“新”。
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)
发布于 2022-06-30 05:15:16
filter方法针对您提供的函数运行所有数组元素,如果它们符合条件的话。然后它将创建一个新的数组并存储该元素。.filter()不修改原始数组,它被认为是不可变的。
您可以只读取原始数组的值,但不能修改它。
https://stackoverflow.com/questions/72810476
复制相似问题