map() - Transform Elements in JavaScript

From the JavaScript Array Methods cheat sheet ยท Transformation Methods ยท verified Jul 2026

map() - Transform Elements

Create a new array by transforming each element

javascript
// Create new array by transforming each element
const doubled = [1, 2, 3].map(x => x * 2);
// [2, 4, 6]

const users = [{name: 'John', age: 30}];
const names = users.map(u => u.name);
// ['John']

// With index
const indexed = ['a', 'b'].map((val, i) => `${i}: ${val}`);
// ['0: a', '1: b']
๐ŸŸข Essential - Most commonly used array method
๐Ÿ’ก Returns new array, doesn't modify original
โšก Perfect for data transformation and React rendering
๐Ÿ“Œ Always returns array of same length as original
๐Ÿ”— Related: forEach (for side effects), filter (for selection)

More JavaScript tasks

Back to the full JavaScript Array Methods cheat sheet