javascript / beginner
Snippet
Iterating with Each Blocks
The {#each} block allows you to loop over an array and render an element for every item in that list.
snippet.js
javascript
1
2
3
4
5
6
7
8
9
<script>let colors = ['Red', 'Green', 'Blue'];</script><ul>{#each colors as color}<li>{color}</li>{/each}</ul>
svelte
Breakdown
1
{#each colors as color}
Starts the loop, assigning each array element to the variable 'color'.
2
{/each}
Closes the loop block.