February 2018
Intermediate to advanced
298 pages
8h 22m
English
The map() method creates and returns a new array and passes every element of that array to the supplied function. Take a look at this example:
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];const squaredNums = arr.map( num => num**2 );console.log(squaredNums);
The output is:
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
In the preceding function, when you run map on arr, every value is passed one by one into the supplied function. The value is contained as num. Since we're using the ES6 arrow function notation, everything looks extremely concise and neat.
Read now
Unlock full access