[0, 1, 2, 3, 4].reduce(function(accumulator, currentValue, currentIndex, array){
return accumulator + currentValue;
});
//返回 10
//箭头函数表示
[0, 1, 2, 3, 4].reduce((accumulator, currentValue, currentIndex, array) => { return accumulator + currentValue; }, 10 );
//返回 20
accumulator 累计器
currentValue 当前值
currentIndex 当前索引
array 数组
网友评论