Array.prototype.map
Creates a new array populated with the results of calling a provided function on every element in the calling array
Syntax
array.map(callbackFn, thisArg?)Parameters
| Parameter | Type | Description |
|---|---|---|
| callbackFn | (element, index, array) => T | Function that produces an element of the new array |
| thisArg | any | Value to use as this when executing callbackFn |
Return Value
A new array with each element being the result of the callback function
Examples
const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map(n => n * 2);
console.log(doubled); // [2, 4, 6, 8, 10]const users = [
{ name: 'Alice', age: 25 },
{ name: 'Bob', age: 30 }
];
const names = users.map(user => user.name);
console.log(names); // ['Alice', 'Bob']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
Array.prototype.filterCreates a shallow copy of a portion of a given array, filtered down to just the elements that pass the test implemented by the provided function
Array.prototype.forEachExecutes a provided function once for each array element
Array.prototype.flatMapReturns a new array formed by applying a given callback function to each element of the array, then flattening the result by one level
Array.prototype.reduceExecutes a user-supplied reducer callback function on each element of the array, passing in the return value from the calculation on the preceding element
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.