当前位置:网站首页>js:Array. Reduce cumulative calculation and array consolidation
js:Array. Reduce cumulative calculation and array consolidation
2022-06-29 08:00:00 【Pengshiyu】
grammar
array.reduce(function(prevValue, currentValue, currentIndex, arr), initialValue)
| Parameters | describe |
|---|---|
| prevValue | It's necessary . Previous value , Or the return value after calculation . |
| currentValue | It's necessary . The current element |
| currentIndex | Optional . Index of the current element |
| arr | Optional . The array object to which the current element belongs . |
| initialValue | Optional . The initial value passed to the function |
Example : Cumulative calculation
let list = [1, 2, 3, 5];
let result = list.reduce((prevValue, currentValue)=>{
return prevValue + currentValue;
}, 0);
console.log(result);
// 11
Example : Merge array
let list = [[1, 2, 3], [], [8, 9]];
let result = list.reduce((prevArr, currentArr)=>{
return prevArr.concat(currentArr);
}, []);
console.log(result);
// [ 1, 2, 3, 8, 9 ]
Reference resources
https://www.runoob.com/jsref/jsref-reduce.html
边栏推荐
- js异或混淆代码
- Prompt during packaging: property 'sqlsessionfactory' or 'sqlsessiontemplate'‘
- Vulnhub's dc6 target
- Protobuf binary file learning and parsing
- Software testing
- Viewing application and installation of Hana database license
- Oracle batch insert data - insert ethnic data
- 数组知识点小结
- SQL injection bypass (6)
- After crossing, she said that the multiverse really exists
猜你喜欢

征文投稿丨使用轻量应用服务器搭建博客环境

Code:: blocks code formatting shortcuts
![Detailed explanation of communication principle between [industrial control old horse] single chip microcomputer and Siemens S7-200](/img/56/b300c0c3606dbc328e301092615bff.jpg)
Detailed explanation of communication principle between [industrial control old horse] single chip microcomputer and Siemens S7-200

C#Mqtt订阅消息

C实战——高配版贪吃蛇游戏设计

软件测试鸾音鹤信

Roblox剑九之剑二

Alicloud access resource: nosuchkey

手撕二叉搜索树(Binary Search Tree)

华为云的AI深潜之旅
随机推荐
Up and down transitions in polymorphism
MySQL系统关键字汇总(官网)
Little white battle pointer (Part 1)
Protobuf binary file learning and parsing
产品经理应该学习墨刀还是Axure?
Explanation of swing transformer theory
基础语法 - 位运算
Interviewer: why does database connection consume resources? Where are the resources consumed?
呕心沥血总结出来的MySQL常见错误以及解决方法(一)
Codeforces Round #799 (Div. 4)
How to permanently set Mysql to utf8 encoding?
征文投稿丨使用轻量应用服务器搭建博客环境
声波通讯 - 流式数据处理 - 窗口对齐
Vulnhub's dc7 target
mysql 开启日志功能
qtcreator设置字符集
Detailed explanation of communication principle between [industrial control old horse] single chip microcomputer and Siemens S7-200
SAP ui5 Beginner (I) Introduction
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
Common MySQL errors and solutions summarized painstakingly (I)