map
map (pure)
Create a new array by transforming each element according to a function passed as an argument. These callback functions are often written as arrow functions.
let arr = [1, 2, 3, 4];
const newArr = arr.map((value) => value - 1);
console.log(newArr);
// => [0, 1, 2, 3]
console.log(arr);
// => [1, 2, 3, 4]
It is worth noting that the resulting array will always be of the same length as the original.
Backlinks