Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Routing and Application Architecture
Stage 5: Specialization (pick ONE)

Part 04 / Topic 1 of 8

Turning an array into a list of elements

.map() takes an array and returns a new array built by transforming every entry - you already know this from plain JavaScript. Inside JSX, nothing changes: {numbers.map(n => n * 2)} gives you an array of numbers; {items.map(item => <li>{item.name}</li>)} gives you an array of <li> elements, and React renders an array of elements exactly the way it renders one.

// examples/01_menu_list_map.jsx
export const tiffinMenu = [
  { id: "d1", name: "Masala Dosa", price: 90 },
  { id: "d2", name: "Idli Sambar", price: 70 },
  { id: "d3", name: "Veg Biryani", price: 180 },
];

export function MenuList({ items }) {
  return (
    <ul className="menu-list">
      {items.map((item) => (
        <li key={item.id}>
          {item.name} — {`₹${item.price}`}
        </li>
      ))}
    </ul>
  );
}

Rendering <MenuList items={tiffinMenu} /> and reading the result with Testing Library really shows three <li> elements, in the array's own order (React 19.3.1, examples/01_menu_list_map.test.jsx):

Masala Dosa — ₹90
Idli Sambar — ₹70
Veg Biryani — ₹180

An empty array renders an empty <ul> - no special casing needed, [].map(...) is just []. Section 6 covers the case this course actually wants you to show instead of a blank list: a deliberate empty-state message.

Done here? The practice set for Part 4 — including the solutions — is on the part page.

Search the guide