functionwork(n){returnnewPromise(resolve=>{setTimeout(()=>{resolve(n*10);},200);})}(asyncfunction(){array=[1,2,3];for(leti=0;i<array.length;i++){// it WILL wait here. constresult=awaitwork(array[i]);// result is 10, 20, 30 as expectedconsole.log(result);}})();
async function doesn't work inside
for loopInstead, you push all promises in an array then resolve them with
Promise.allActually,
asyncworks as expected in for loop.Yes, that's exactly it!