How to use the map function in javascript?

The map method creates a new array by calling a function on every array element.

Example:


  let numbers = [1, 2, 3, 4, 5];
  let squares = numbers.map(function(num) {
      return num * num;
  });
  console.log(squares);  // Outputs: [1, 4, 9, 16, 25]
  

Beginner's Guide to JavaScript