Svelte · Junior · Question 18 of 76

How do you render a list?

{#each todos as todo (todo.id)}
  <li>{todo.text}</li>
{:else}
  <li>Nothing to do</li>
{/each}

Explanation

The expression in parentheses is the key. It helps Svelte insert and remove items precisely instead of updating existing DOM.

Further reading

Problem with a question

Svelte · Junior · question 18

Test yourself

Take the Svelte · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz