当 Promise.all
完成时,它返回一个包含数据的数组。在我的例子中,数组只是数字:
[
[ 1, 4, 9, 9 ],
[ 4, 4, 9, 1 ],
[ 6, 6, 9, 1 ]
]
该数组可以是任意大小。
目前我正在这样做:
let nums = []
data.map(function(_nums) {
_nums.map(function(num) {
nums.push(num)
})
})
有没有其他方法可以做到这一点? lodash
是否有任何功能可以做到这一点?
原文由 BugHunterUK 发布,翻译遵循 CC BY-SA 4.0 许可协议
ES2019 引入了
Array.prototype.flat
这大大简化了这个:原始答案
使用
reduce
和concat
:或者,
concat
和apply
: