DEV Community

Discussion on: How The Hell Do I use Map?

Collapse
 
wuz profile image
Conlin Durbin

I think it depends. I mostly write React these days and I almost never use a for loop. The nice thing about maps is they implictly return an array, allowing you to avoid all imperative code. They also make it so you are not writing code with side effects.

Performance might be a reason for a for loop, but that eliminates the gains that you get from having immutable data structures in your code.

Collapse
 
nielsbom profile image
Niels Bom

Though I agree that immutability and functional programming are very useful, and I like writing that style of code, you can always come across a situation where a certain amount of performance is necessary so that creating a lot of new data structures or very big ones (like map does) is not an option.