js使用reduce对数组求和
let arr = [3, 4, 5, 2, 1];
let sum = arr.reduce((pre, next) => {
pre += next;
return pre;
}, 0)
console.log('结果:', sum);
这是我的签名
let arr = [3, 4, 5, 2, 1];
let sum = arr.reduce((pre, next) => {
pre += next;
return pre;
}, 0)
console.log('结果:', sum);