Lets say that I have this code:
const array = [1, 2, 3]
let counter = 0
array.map(async (item) => {
console.log(await item, ++counter)
console.log(await item, ++counter)
})
the expected output would be
1, 1
1, 2
2, 3
2, 4
3, 5
3, 6
but what I am getting is this
1, 1
2, 2
3, 3
1, 4
2, 5
3, 6
it seems like the first await call is running first for the whole array, then the second one in being run, why is this happening?
awaita number?await. That's the entirety of the explanation about your question. But is it really useful to solve your problem? You most likely shouldn't be using an async in a.map(). Unless you put that in aPromise.all()