Array.map
Transform every item into a new array of the same length.
map always returns a new array. Length stays
the same: one output per input. Use it for labels, scaled numbers, or
turning objects into strings.
Before
After (new array)
Important JavaScript
const scores = [10, 20, 30];
const labels = scores.map(function (n) {
return n + " pts";
});
// ["10 pts", "20 pts", "30 pts"]
const doubled = scores.map((n) => n * 2);
// [20, 40, 60] — same length, new array
const players = [
{ name: "Ava", score: 88 },
{ name: "Ben", score: 64 }
];
const lines = players.map((p) => p.name + ": " + p.score);
// ["Ava: 88", "Ben: 64"]