Course contentsShow
← JavaScript
Lesson 850 of 2,72320. Array Iteration and TransformationFree lesson

Map Returns a New Array

Understanding that map creates a new array without mutating the original.

Map Returns a New Array

What you'll learn: How map() creates a brand new array instead of modifying the one you started with.

When you call map() on an array, it never changes the original array. Instead, it builds and returns a completely new array with the transformed elements. This makes map() a non-mutating method—one of the safer tools in your array toolkit.

Why This Matters

Think of map() like a photocopier that can edit while copying. You put in your original document (the array), it reads each page (element), makes modifications to the copies, and hands you back a completely separate document. Your original stays pristine on your desk.

const numbers = [1, 2, 3, 4];
const doubled = numbers.map(num => num * 2);

console.log(numbers); // [1, 2, 3, 4] — unchanged!
console.log(doubled); // [2, 4, 6, 8] — brand new array

The New Array Is Always Created

Even if you don't store the result, map() still creates a new array (though it gets discarded). This is different from forEach(), which simply executes a function and returns undefined.

const colors = ['red', 'blue', 'green'];

const result = colors.map(color => color.toUpperCase());
console.log(result); // ['RED', 'BLUE', 'GREEN']
console.log(colors); // ['red', 'blue', 'green'] — untouched

This behavior makes map() perfect for functional programming patterns where you want to avoid side effects and keep your data transformations predictable.

Key Takeaway: map() always returns a brand new array with transformed elements, leaving your original array completely unchanged—making it a safe, non-mutating method for data transformation.