首页 > Web开发 > 详细

js reduce()方法使用

时间:2018-09-06 17:49:17      阅读:132      评论:0      收藏:0      [点我收藏+]

reduce() 方法接收一个函数作为累加器,数组中的每个值(从左到右)开始缩减,最终计算为一个值。

reduce() 可以作为一个高阶函数,用于函数的 compose。

注意: reduce() 对于空数组是不会执行回调函数的。

语法:

        array.reduce(function(total, currentValue, currentIndex, arr), initialValue)

       arrray:数组

       total:初始值(必需)  

       currentValue:当前值(必需)

       currentIndex:当前元素索引

       arr:当前元素所属对象   

       initialValue:传递给数组的初始值

js reduce()方法使用

原文:https://www.cnblogs.com/gpzhen/p/9599278.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!