Lists
Render lists with map and key
Key points
- Use map to show an array on screen. It applies the same JSX shape to each item in the array
- Give the outermost element in map a key (a name tag) that's different for every item
- For key, use a value unique to that item, like an id. Avoid the array position (index), because it shifts when you sort or delete
Try it
- Add "Grapes" to the array (it appears on screen automatically)
- Show only items priced at $1 or more (hint: filter before map)
- Remove key={fruit.id} and see what shows up in the Console