JS之reduce
来源:互联网 发布:淘宝详情页的尺寸 编辑:程序博客网 时间:2024/05/20 01:33
以前没接触到reduce
忽然遇见了这么个题:
martix = [[1,2],[3,4][5,6]]; var fl = martix.___(function(a,b)____); console.log(fl)//输出[1,2,3,4,5,6]
看看reduce
[0, 1, 2, 3, 4].reduce(function(previousValue, currentValue, index, array) { return previousValue + currentValue;});
“MDNreduce”
reduce的callback含四个参数 previousValue, currentValue, index, array
reduce的作用
If initialValue is provided in the call to reduce, then previousValue will be equal to initialValue and currentValue will be equal to the first value in the array. If no initialValue was provided, then previousValue will be equal to the first value in the array and currentValue will be equal to the second.
有初始值,将初始值作为previousValue, 数组第0个值作为currentValue,以此类推
无初始值,将第0个值作为previousValue,数组第1个值作为currentValue,以此类推
现在懂了
martix = [[1,2],[3,4][5,6]]; var fl = martix.reduce(function(a,b){ return a.concat(b);}); console.log(fl)
0 0
- JS之reduce
- Array数组(JS)之map与reduce方法
- js的数组知识之深入理解map和reduce
- js reduce用法
- JS中的map、reduce
- js Array.prototype.reduce()
- Js的reduce()方法
- js reduce方法
- Underscore之Map Reduce
- Hadoop之Map-Reduce
- python之map/reduce
- JavaScript 之 reduce
- Python之map()/reduce()
- 【js】Array.prototype.reduce方法
- JS Array ...map ,reduce , filter..
- JS学习-map()和reduce()
- js Array.prototype.reduce使用
- hadoop 学习之Map/Reduce
- HDU2119Matrix(最小点集覆盖)
- 生产环境中跨节点隔离网络构架解析
- 华为OJ(字符串分隔)
- Poj 1061青蛙的约会 扩展欧几里德
- 六进制+括号替换 SRM 628 Division Two - Level Two BracketExpressions
- JS之reduce
- Activity跳转Flag详解
- 系统性能调优
- Android之HttpClient的使用方法
- hdu5402 Travelling Salesman Problem
- Eddy's digital Roots HDU杭电1163 【一个比较实用的定理】
- HTTP协议总结
- C语言之文件操作08——总结
- 差分约束系统详解