ForEach asynchronous Javascript in question

Try next day the call await Promise forEach function () method as follows:

was arr = [1,2,3]

arr.forEach(async (v,i,a)=>{

  await Promise()

})

I found did not follow the imagination on a Promise to wait until the process is completed after the implementation of the next Promise.

After access to information that the actual function forEach internal asynchronous encountered this problem, use a for loop, as follows:

was arr = [1,2,3]

for(let i=0;i<arr.length;i++){

  await Promise()

}

Can solve the problem, the specific principles until the next supplementary

 

Guess you like

Origin www.cnblogs.com/gs456/p/11002162.html