20 JavaScript tools to blow your mind

05. Replace 'for' loops with 'map' to keep things simple

Let’s pretend we have an array of numbers and we’d like to produce another array by doubling all of the numbers from the first array. One way to do this is to declare an empty array, write a for loop, and set a number in the second array by looking up the index on the first array and doubling it.

Thank you for reading 5 articles this month* Join now for unlimited access

Enjoy your first month for just £1 / $1 / €1

*Read 5 free articles per month without a subscription

Join now for unlimited access

Try first month for just £1 / $1 / €1

Sergio Cruz is a developer, instructor, and the author of Code School’s ‘Powering Up With React’ course. He is passionate about learning and sharing knowledge, and often speaks at web events