Use an {#each}…{/each}
block to iterate over an array in a template.
Use an {#if}…{/if}
block to conditionally render HTML.
Use {:else}
and {:else if …}
directives to add more conditions.
Svelte uses {#each}
and {#if}
template directives to render lists and conditionally render content.
In this example, we'll render a list of todos and display a message based on the remaining amount of todos.
Use an {#each}…{/each}
block to iterate over an array in a template.
Use an {#if}…{/if}
block to conditionally render HTML.
Use {:else}
and {:else if …}
directives to add more conditions.
The index of the current iteration is also available in {#each}
.
You may also specify a key in an {#each}
block. A key is a unique identifier for a list item. Setting a keys is recommended so Svelte can correctly update the DOM when a list item's index changes.
Further reading on this topic.