在 JavaScript/TypeScript 中,如果你要对数组进行异步处理,以下两种为较优解。
[1,2,3].forEach(async (v)=>console.log(v))
console.log('done')
await Promise.all([1,2,3].forEach(async (v)=>console.log(v)))
console.log('done')
const arr = [1,2,3]
for (const v of arr) {
const data = await xxx()
console.log(v, data)
}
此文由 Mix Space 同步更新至 xLog
原始链接为 https://xrzyun.eu.org/posts/devlogs/async-of-array-in-js