JavaScript array .reduce with async/await
2022-08-30 04:43:00
似乎在将 async/await 与 .reduce() 合并时遇到了一些问题,如下所示:
const data = await bodies.reduce(async(accum, current, index) => {
const methodName = methods[index]
const method = this[methodName]
if (methodName == 'foo') {
current.cover = await this.store(current.cover, id)
console.log(current)
return {
...accum,
...current
}
}
return {
...accum,
...method(current.data)
}
}, {})
console.log(data)
在完成之前记录该对象...data
this.store
我知道你可以使用异步循环,但这适用于吗?Promise.all
.reduce()