博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JavaScript reduce()函数
阅读量:2504 次
发布时间:2019-05-11

本文共 726 字,大约阅读时间需要 2 分钟。

reduce() is another important method of an array.

reduce()是数组的另一个重要方法。

reduce() executes a callback function on all the items of the array and allows to progressively compute a result. If initialValue is specified, accumulator in the first iteration will equal to that value.

reduce()在数组的所有项目上执行回调函数,并允许逐步计算结果。 如果指定了initialValue ,则第一次迭代中的accumulator将等于该值。

a.reduce((accumulator, currentValue, currentIndex, array) => {  //...}, initialValue)

Example:

例:

[1, 2, 3, 4].reduce((accumulator, currentValue, currentIndex, array) => {  return accumulator * currentValue}, 1)// iteration 1: 1 * 1 => return 1// iteration 2: 1 * 2 => return 2// iteration 3: 2 * 3 => return 6// iteration 4: 6 * 4 => return 24// return value is 24

翻译自:

转载地址:http://gpqgb.baihongyu.com/

你可能感兴趣的文章
Atitit.git的存储结构and 追踪
查看>>
atitit 读书与获取知识资料的attilax的总结.docx
查看>>
B站 React教程笔记day2(3)React-Redux
查看>>
找了一个api管理工具
查看>>
C++——string类和标准模板库
查看>>
zt C++ list 类学习笔记
查看>>
git常用命令
查看>>
探讨和比较Java和_NET的序列化_Serialization_框架
查看>>
1、jQuery概述
查看>>
数组比较大小的几种方法及math是方法
查看>>
FTP站点建立 普通电脑版&&服务器版
查看>>
js 给一段代码,给出运行后的最终结果的一些综合情况、
查看>>
webservice 详解
查看>>
js自动补全实例
查看>>
VS无法启动调试:“生成下面的模块时,启用了优化或没有调试信息“
查看>>
npm 安装 sass=-=-=
查看>>
WINFORM中加入WPF控件并绑定数据源实现跨线程自动更新
查看>>
C#类对象的事件定义
查看>>
各类程序员学习路线图
查看>>
HDU 5510 Bazinga KMP
查看>>