🎉
💨
Transform every item! Like sending trains through a magic tunnel!
The map() Method
The map() method creates a new array by transforming every item.
Each item goes through a function, and the results become a new array!
💡
💨
How map() Works
1const numbers = [1, 2, 3, 4, 5];23// Double every number4const doubled = numbers.map(n => n * 2);5console.log(doubled); // [2, 4, 6, 8, 10]67// Square every number8const squared = numbers.map(n => n * n);9console.log(squared); // [1, 4, 9, 16, 25]1011// Original is unchanged12console.log(numbers); // [1, 2, 3, 4, 5]
🤔
💨
map() Creates a NEW Array
map() doesn't change the original array - it makes a brand new one with the transformed items!
Think of it like a transformation tunnel: the original train cars go in, and completely new, transformed cars come out the other side!
🎮
Try It Yourself!
Send your numbers through the transformation tunnel! Pick a transformation to apply to all items.