无涯教程-reduceRight()函数

54 阅读1分钟

reduceRight()方法将数组元素计算为一个值(从右到左),以将其简化为单个值。

reduceRight() - 语法

array.reduceRight(callback[, initialValue]);    
  • callback       -  对数组中的每个值执行的函数。

  • initialValue -  用作首次调用回调的第一个参数的对象。

reduceRight() - 返回值

返回数组的缩减右单值。

reduceRight() - 示例

var total=[0, 1, 2, 3].reduceRight(function(a, b){ return a + b; }); 
console.log("total is : " + total );    

运行上面代码输出

total is : 6

参考链接

www.learnfk.com/es6/es6-arr…