0Pricing
Sveltejs Academy · Lesson

Nested {#each} and Keyed Updates

Handle nested lists and ensure efficient DOM updates with keyed each blocks.

Two Dimensions

Nest {#each} blocks to render tables, grids, or trees.

{#each rows as row, i}
  <tr>
    {#each row as cell, j}
      <td>{cell}</td>
    {/each}
  </tr>
{/each}

Keys at Each Level

Add keys at every level for efficient updates.

{#each rows as row (row.id)}
  {#each row.cells as cell (cell.id)}
    ...
  {/each}
{/each}

All lessons in this course

  1. {#if} {#else if} {#else}
  2. {#each} with Index and Key
  3. {#key} for Forcing Re-render
  4. Nested {#each} and Keyed Updates
← Back to Sveltejs Academy