LESSON 04 / 05

Lists & Keys

Turn arrays of data into lists of components with map — and give each item a stable key so React can track it.

🎓Mediumlevel
⏱️30 minto finish
✏️1activities

📂 Components & JSX🏷️ React

🎯 By the end of this lesson you can…

  • Render arrays with map
  • Choose good keys
  • Filter and sort before rendering
⚛️ React App.jsx 👆 Tap a line to explain it
1const students = [2  { id: 1, name: "Asha", marks: 91 },3  { id: 2, name: "Ben", marks: 58 },4  { id: 3, name: "Chen", marks: 76 },5];6 7function App() {8  const passed = students.filter((s) => s.marks >= 60).sort((a, b) => b.marks - a.marks);9  return (10    <ol>11      {passed.map((s) => (12        <li key={s.id}>13          {s.name} — {s.marks}14        </li>15      ))}16    </ol>17  );18}
🛠️ Menu list

Render the menu array as a list showing name – ₹price for each dish, with a 🌱 after vegetarian dishes. Use the id as the key.

📌 Key takeaways

  • {items.map(item => <li key={item.id}>{item.name}</li>)}
  • Keys must be unique and stable — use ids, not array indexes, when items can move.
  • Transform data first (filter/sort), then map to JSX.

Finished reading & practising?

Saved in this browser. Create a free account to keep it forever.