Array.prototype.map()

map(callbackFn, thisArg?)
Returns: Array · Added in vES5 · Updated March 13, 2026 · Array Methods
array map functional transformation

map() creates a new array populated with the results of calling a provided function on every element in the calling array. It transforms data by applying a function to each item, making it one of the most commonly used array methods in JavaScript.

Syntax

map(callbackFn)
map(callbackFn, thisArg)

Parameters

ParameterTypeDefaultDescription
callbackFnFunctionFunction called for each element, returning a new value
thisArganyundefinedValue to use as this when executing callbackFn

The callback function receives three arguments:

ArgumentTypeDescription
elementanyCurrent element being processed
indexnumberIndex of current element
arrayArrayArray that map was called upon

Examples

Basic usage

const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map(n => n * 2);
console.log(doubled);
// [2, 4, 6, 8, 10]

Transforming objects

const users = [
  { name: 'Alice', age: 25 },
  { name: 'Bob', age: 30 },
  { name: 'Charlie', age: 35 }
];

const names = users.map(user => user.name);
console.log(names);
// ['Alice', 'Bob', 'Charlie']

Using index parameter

const fruits = ['apple', 'banana', 'cherry'];
const indexed = fruits.map((fruit, i) => `${i + 1}. ${fruit}`);
console.log(indexed);
// ['1. apple', '2. banana', '3. cherry']

Common Patterns

Chaining with other array methods

const numbers = [1, 2, 3, 4, 5];

const result = numbers
  .filter(n => n > 2)
  .map(n => n * 10);
  
console.log(result);
// [30, 40, 50]

Extracting specific properties

const products = [
  { id: 1, price: 100, name: 'Widget' },
  { id: 2, price: 200, name: 'Gadget' }
];

const prices = products.map(p => p.price);
console.log(prices);
// [100, 200]

Creating objects from arrays

const ids = [1, 2, 3];
const objects = ids.map(id => ({ id, status: 'active' }));
console.log(objects);
// [{ id: 1, status: 'active' }, { id: 2, status: 'active' }, { id: 3, status: 'active' }]

Key Behaviors

  • map() does not mutate the original array
  • map() returns a new array with the same length as the original
  • map() skips holes in sparse arrays but preserves them
  • map() always returns a new array—even if all elements remain unchanged

See Also