【问题标题】:can someone please tell me why is "previousValue" here in the code is "array type"?有人可以告诉我为什么代码中的“previousValue”是“数组类型”吗?
【发布时间】:2022-03-24 23:24:39
【问题描述】:

// 在新数组中控制台复制的逻辑
让 myArray = ['a', 'b', 'a', 'b', 'c', 'e', 'e', 'c', 'd', 'd', 'd', 'd '] 让 myArrayWithNoDuplicates = myArray.reduce(function (previousValue, currentValue) { if (previousValue.indexOf(currentValue) === -1) { previousValue.push(currentValue) } 返回上一个值 }, [])

  console.log(myArrayWithNoDuplicates)

【问题讨论】:

标签: methods reduce


【解决方案1】:

previousValue 是您的累加器的先前值。您的累加器是 [] 一个数组,因此 previousValue 必须是数组

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-17
    • 2020-02-21
    • 2020-10-30
    • 2010-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多