reduce用法

2019-08-29  本文已影响0人  郭海杰

[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 数组

上一篇 下一篇

猜你喜欢

热点阅读