关于 js 并发请求数据的问题

const ids = [1, 2, 3]
const resArr = []
// 1
ids.forEach(id => api(id).then(res => resArr.push(res))
// 2
Promise.all(ids.map(id => api(id).then(res => resArr.push(res))))
posted @ 2021-04-01 16:52  FE-神鸟  阅读(192)  评论(0编辑  收藏  举报