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:
  1. Use map to extract product names from an array of products
  2. Use map to create formatted price strings
  3. Use map to transform products into a different shape
💰 Map syntax:
const result = array.map((element) => transformedValue)
💰 TypeScript infers the result type from what you return:
const names = products.map((p) => p.name) // Array<string>

Please set the playground first

Loading "Map"
Loading "Map"
Login to get access to the exclusive discord channel.