DEV Community

Discussion on: Modern JS, when to use map or for?

Collapse
 
vonheikemen profile image
Heiker • Edited

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.

Collapse
 
altneko profile image
NekoAlt

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.