Map
Map
π¨βπΌ The
map method creates a new array by transforming each element.const numbers = [1, 2, 3]
const doubled = numbers.map((n) => n * 2)
// [2, 4, 6]
The callback receives each element and returns the transformed value.
π¨ Open
and:
- Use
mapto extract product names from an array of products - Use
mapto create formatted price strings - Use
mapto transform products into a different shape
π°
map returns a new array of whatever your callback returns.