DEV Community

Elid
Elid

Posted on

The JS map() method

The map() method in JavaScript returns to you a new array by calling a function for every element it does not mutate. The original array just creates a copy this is used a lot in React so is something good to know along with other JS methods.

const numbersList = [1, 2, 4, 5];

// example
const mapArr = numbersList.map((n) => n + 1);
console.log(mapArr)

// Output [2, 3, 5, 6];
// I will also console the original array to see no changes made
console.log(numbersList);

Top comments (0)