Javasscript
[ES5]array.reduce() 可以用来扁平数组,对数组做累加操作
[0,1,2,3,4].reduce(function(previousValue,currentValue, index, array){
return previousValue + currentValue;
});
var flattened = [[0, 1], [2, 3], [4,5]].reduce(function(a, b) {
return a.concat(b);
});
// flattened is [0, 1, 2, 3, 4, 5]
网友评论