The JS map() method
Elid

Elid @elidvenega

About: Hello, I'm an inspiring front-end developer.

Joined:
Nov 5, 2022

The JS map() method

Publish Date: May 13 '24
0 0

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);

Comments 0 total

    Add comment