When to use .map? When you want to transform the items in the array. That's it. If you want to transform the array in any way, by removing an item or adding one, .map is not the ideal method. If you just want to loop it's perfectly fine to use a for...of loop.
That said. I think the second example runs faster because you don't wait for each query, they all run concurrently.
When to use
.map
? When you want to transform the items in the array. That's it. If you want to transform the array in any way, by removing an item or adding one,.map
is not the ideal method. If you just want to loop it's perfectly fine to use afor...of
loop.That said. I think the second example runs faster because you don't wait for each query, they all run concurrently.
Thanks for your feedback, Heiker!
I see now why the second code could run faster. Thinking in a functional way is something I should practice more.