0Pricing
Sveltejs Academy · Lesson

{#each} with Index and Key

Loop over arrays and objects, accessing index and key values.

The each Block

{#each list as item} iterates over an array and renders the markup once per element.

{#each colors as color}
  <li>{color}</li>
{/each}

Destructuring

Destructure the item shape inline for cleaner templates.

{#each users as { id, name }}
  <li>{name}</li>
{/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