let a = new Promise((res, rej) => {
res(1)
}).catch(err=>console.log(err))
let b = new Promise((res, rej) => {
setTimeout(() => {
rej(2)
}, 2000)
}).catch(err=>console.log(err))
let c = new Promise((res, rej) => {
res(3)
}).catch(err=>console.log(err))
const arr = [a, b, c]
async function bb() {
let arr1 = [];
for (let i = 0; i < arr.length; i++) {
let h = await arr[i]
arr1.push(h)
}
return arr1
}
bb().then(res => {
console.log(res); //[1, undefined, 3]
});
记录一下给自己看的。