Map method in JavaScript

Nilesh Saini
May 7, 2022

Concise explanation of map() method in Js

Photo by GeoJango Maps on Unsplash
  1. Creates a new array.
  2. Iterates through an array.
  3. Runs a callback function for each element in the array.
  4. Adds the result of that callback function to the new array.
  5. Returns the new array.

Note: map() always returns a new array of the same length.

How does it work?

Note: learn more about callback function parameters here.

Examples:

  1. Triple the value of each element in the given array.

2. Return a new array with the square root of all the values of the given array.

--

--

Nilesh Saini

Web Developer/ Front-end engineer who loves solving Rubik's Cube