When should I use .map()? When should I use a for loop?


#1

Question

When should I use .map()? When should I use a for loop?

Answer

Use .map() when you want to create a new array of transformed values of the original array by iterating over and calling a function on every element of said original array. Use a for loop when you need a less specialized and more flexible iterator.