javascript array.prototype.reduce()

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript array.prototype.reduce()相关的知识,希望对你有一定的参考价值。

const array1 = [1, 2, 3, 4];
const reducer = (accumulator, currentValue) => accumulator + currentValue;

// 1 + 2 + 3 + 4
console.log(array1.reduce(reducer));
// expected output: 10

// 5 + 1 + 2 + 3 + 4
console.log(array1.reduce(reducer, 5));
// expected output: 15

以上是关于javascript array.prototype.reduce()的主要内容,如果未能解决你的问题,请参考以下文章