How to make array.forEach(asyncfn) synchronized?

后端 未结 4 1992
渐次进展
渐次进展 2021-01-27 06:17

Say I have an array and I want to perform an async-function on each element of the array.

let a = [x1, x2, x3]

// I want to
await a.forEach(async (x) => {...         


        
4条回答
  •  孤城傲影
    2021-01-27 07:01

    Is there any specific event on which these function will be called ?
    if yes can be achieved through **closure** in javascript.
    

    right now your function will be called with last value in array when you invoke it

提交回复
热议问题