How to use the map() method?

const numbers = [1, -9, 42]

const divideByTwo = numbers.map(number => number / 2)

//output: [0.5, -4.5, 21]
console.log(divideByTwo)
Copy

September 1st, 2019

# map() - Applying a function to every element of an array

Add to bookmarks

map() is calling a function on every element of the array and creates a new array.

Tracking with Matomo to improve the UX. See Privacy Policy for more details.