Array.prototype.map(callback) builds a new array by calling callback on every element and collecting each return value. Length stays the same; the source array is not mutated. For side effects only, prefer forEach(). To keep some items and drop others, use filter().
Remember
array.map(callback)
array.map((element, index, array) => ...)
[1, 2, 3].map(n => n * 2) → [2, 4, 6]
["a", "b"].map(s => s.toUpperCase()) → ["A", "B"]
returns a new array (same length)
original array unchanged
always return a value from the callback
Syntax
Call array.map. Start with this line.
JavaScript
array.map(callback)
Call
What it does
array.map(callback)
Primary signature.
array.map(...)
Call with the arguments your case needs.
Built into JavaScript. Call map(...) on an array instance — no import required.
Library declarations
JavaScript
array.map(callback)
Parameters
Parameter
Description
callback
Required. Runs once per element; return the new value
map collects. Each return value becomes part of mapped.
forEach discards. Even if you return a value, the method result is undefined.
Pick by intent. Need a new array → map; only side effects → forEach.
Avoid the trap. Do not assign forEach to a variable expecting data.
Compatibility
Browser & Runtime Support
Array.prototype.map() is part of ES5 (2009). It has been available in evergreen browsers and Node.js for a long time.
✓ Baseline · ES5
Array.prototype.map()
Supported in all modern browsers, Internet Explorer 9+, and every current Node.js release.
99%Browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
Array.map()Excellent
Bottom line: Safe everywhere. Prefer map() when you need a new array; use forEach() only for side effects.
Frequently Asked Questions
map() calls a callback on every element and collects each return value into a new array of the same length. The original array is not changed.
No. map() always returns a new array. If your callback mutates objects inside the source array, those shared objects can still change — but the array shell is new.
map() returns a new transformed array. forEach() returns undefined and is meant for side effects like logging.
That slot in the new array becomes undefined. Always return a value when you need meaningful results.
Yes. The callback receives (element, index, array). Use index when the position matters.
map() is ES5 (2009). It works in all modern browsers and has been supported in Internet Explorer 9+.