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)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay