Favorites

JavaScript Array.prototype.map() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Array.prototype.map()
JavaScript Array Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The map() method creates a new array by calling a function on every element of an array and collecting the results. The original array is not changed.

Description

The map() method of Array instances creates a new array filled with the results of calling a function on every element. It is the usual way to transform a list, for example to turn an array of numbers into their squares, or an array of user objects into an array of names.

The new array always has the same length as the original, and the original array is left unchanged. The callback should return a value for every element; if it doesn't, the corresponding element is undefined. Empty slots in sparse arrays are skipped and stay empty.

Use map() when you want the resulting array. If you only want to run code for each element, use forEach() or a for...of loop instead; to keep only some elements, use filter(). A common mistake is passing a function that takes extra parameters, such as ['1', '2', '3'].map(parseInt), which gives [1, NaN, NaN] because parseInt() receives the index as its radix.

Syntax

array.map(callbackFn)
array.map(callbackFn, thisArg)

Parameters

  • callbackFnA function called once for each element. Its return value becomes the element in the new array. It receives:
    element: the current element.
    index: its index.
    array: the array map() was called on.
  • thisArgOptional. A value to use as this inside callbackFn.

Return Value

A new array, the same length as the original, where each element is the result of the callback.

Example

const numbers = [1, 4, 9];

const doubled = numbers.map(n => n * 2);
console.log(doubled);

const users = [{ name: 'Sam' }, { name: 'Alex' }];
console.log(users.map(u => u.name));

// The index is the second argument
console.log(['a', 'b'].map((letter, i) => letter + i));
console.log(numbers); // unchanged

Browser Support

The following information will show you the current browser support for the Array.prototype.map() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee