javascript map object with array code example
Example 1: how to use the map method in javascript
const numbers = [1, 2, 3, 4, 5];
const bigNumbers = numbers.map(number => {
return number * 10;
});
Example 2: use map to loop through an array
let squares = [1,2,3,4].map(function (val) {
return val * val;
});
Example 3: javascripr array.map
array.map( item => item.id )
array2.map( item => item.toString() )
array2.map( item => item * 3 )
Example 4: javascript map over new array
[...Array(10)].map((a, b) => a)