Example 1 — Map with an Arrow
Pass an arrow into map to transform every item.
const nums = [1, 2, 3];
const doubled = nums.map((n) => n * 2);
console.log(doubled.join(", ")); How It Works
- Callback.
mapcalls the arrow once per item with that item asn. - New array. The results are collected into a new array:
[2, 4, 6].
