Array.prototype.map

Calls a function on each element of an array, and returns an array that contains the results.

Syntax

map(callback, thisArg?)

Parameters

Return value

A new array with all elements transformed using the callback function.

Example

[1, 2, 3].map(x => x * 10)
[10, 20, 30]
["coffee", "tea"].map(s => s.length)
[6, 3]
function myDrinkRating(value) {
  switch (value) {
  case "coffee":
      return `I like ${value}`
  case "tea":
      return `I enjoy ${value}`
  default:
      return `${value} is okay`
  }
}

["coffee", "tea", "water"].map(myDrinkRating)
["I like coffee", "I enjoy tea", "water is okay"]