Array

Array.prototype.map

Creates a new array populated with the results of calling a provided function on every element in the calling array

Syntax

JavaScript
array.map(callbackFn, thisArg?)

Parameters

ParameterTypeDescription
callbackFn(element, index, array) => TFunction that produces an element of the new array
thisArganyValue to use as this when executing callbackFn

Return Value

A new array with each element being the result of the callback function

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]
Practical Example
const users = [
  { name: 'Alice', age: 25 },
  { name: 'Bob', age: 30 }
];
const names = users.map(user => user.name);
console.log(names); // ['Alice', 'Bob']
Advanced Usage
const celsius = [0, 20, 30, 100];
const fahrenheit = celsius.map(c => c * 9/5 + 32);
console.log(fahrenheit); // [32, 68, 86, 212]

Understanding Array.prototype.map

The Array.prototype.map method in JavaScript creates a new array populated with the results of calling a provided function on every element in the calling array. It belongs to the Array object and is one of the most widely used methods for working with array values in modern JavaScript and TypeScript applications.

The method signature is array.map(callbackFn, thisArg?). It accepts 2 parameters: callbackFn, thisArg. When called, it returns a new array with each element being the result of the callback function. Understanding when and how to use map() helps you write more expressive, readable code.

Common use cases for Array.prototype.map include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like array-filter, array-foreach, array-flatmap, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Array.prototype.map is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Array Methods

Other methods in the Array object

Related Tools

More Array Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.