.map() Method

  • Array Methods
  • Array Method
  • Code
  • JavaScript

The .map() array method returns a new array in which each item in the original array has been modified or worked with.

Examples

Example 1

const names = ["Joey", "Tessa", "Sebastian"];const lovesTacos = names.map((name) => `${name} loves tacos!!`);console.log(lovesTacos);// expected output: Array ["Joey loves tacos!!", "Tessa loves tacos!!", "Sebastian loves tacos!!"]

Example 2

const annualGiftAmounts = [120, 72, 60];const monthlySustainerAmounts = annualGiftAmounts.map((gift) => gift / 12);console.log(monthlySustainerAmounts);// expected output: Array [10, 6, 5]

From MDN: The .map() method creates a new array with the results of calling a provided function on every element in the calling array.

See more examples and further documentation here.