← All tutorials

GoCareerGo Tutorials

JavaScript Tutorial

Variables to closures, promises, the DOM and OOP — a complete JS reference.

Array.prototype.map()

Creates a NEW array by calling a function on every element of the original array — never mutates the source.

const nums = [1, 2, 3];
const doubled = nums.map(n => n * 2);
// doubled: [2, 4, 6] — nums is unchanged
  • Signature: arr.map((element, index, array) => newValue)
  • Always returns a new array of the SAME length as the original
  • Use it to transform data, never to just 'loop' (use forEach for that)