Back to Posts

Javascript .map() method

By: Daniel Jimenez | Published on: Aug 03 2020




I remember when I started working with React and I kept seeing this .map() method everywhere.

The .map() method takes each element in an array and transforms it with a function, the map method then returns an array with the same number of items in which it began.

Here we have an array with different Avengers... and Hawkeye

Array with Avengers

Here I created a quick function that will .map() though my list of Avengers and it will return a list with the Avenger and the text "is an Avenger"

Mapping Avengers in a function

And here is my result, I passed an array with 6 items and it returned a new array with 6 items.

Want to see a live Preview? Check out the CodePen


Share:





2022 © Copyright, Daniel Jimenez