const arr = [1, 2, 3, 4, 5];
async function asyncFunction(num) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(num * 2);
}, 1000);
});
}
const promiseList = arr.map(async (num) => {
return await asyncFunction(num);
});
Promise.all(promiseList ).then((results) => {
console.log(results); // [2, 4, 6, 8, 10]
});
js用map处理批量异步方法
最新推荐文章于 2024-04-21 17:10:00 发布