0
Q:

how to use the map method in javascript

const array1 = [1, 4, 9, 16];

// pass a function to map
const map1 = array1.map(x => x * 2);

console.log(map1);
// expected output: Array [2, 8, 18, 32]
16
const numbers = [1, 2, 3, 4, 5]; 

const bigNumbers = numbers.map(number => {
  return number * 10;
});
6
const array = [2, 5, 9];
let squares = array.map((num) => num * num);

console.log(array); // [2, 5, 9]
console.log(squares); // [4, 25, 81]
3

array.map(function(currentValue, index, arr), thisValue)
7
const arr = [1,2,3];
const mapped = arr.map(x => x * x);
4

New to Communities?

Join the community