利用for循环同步执行异步方法
//定义一个异步函数 const foo1 = (i) => { return new Promise((resolve, reject) => { setTimeout(() => { console.log(I) resolve(i) }, 3000) }) } const arr = [1, 2, 3, 4, 5] async function a() { for (var i = 0; i < arr.length; i++) { await foo1(arr[i]) } } a()
君不见,高堂明镜悲白发,朝如青丝暮成雪