> For the complete documentation index, see [llms.txt](https://132oq-szjxckld--diwejk1k2j-1123n.gitbook.io/documentation-studio-shento/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://132oq-szjxckld--diwejk1k2j-1123n.gitbook.io/documentation-studio-shento/getting-started-with-sveltekit/working-with-conditionals-and-loops/looping-through-arrays-lists.md).

# Looping through arrays (lists)

In Svelte you can loop through arrays

```html
{#each [name array] [item-in-array]}
<!-- Code here ->
{/each}
---
<script>
  let list = ['apple', 'banana', 'cherry'];
</script>

<h2>This is a looped component</h2>
<ul>
  {#each list as item}
    <li>{item}</li>
  {/each}
</ul>
```

You can also display something if the array is empty

```html
{#each [name array] [item-in-array]}
<!-- Code here ->
{:else}
<!-- Code here ->
{/each}
```

You can also get the `index (number)` of the `current item` in the array:

```html
{#each [name array] [item-in-array], [index]}
<!-- Code here ->
{/each}
---
<script>
  let list = ['apple', 'banana', 'cherry'];
</script>

<h2>This is a looped component</h2>
<ul>
  {#each list as item, index}
    <li>{index} {item}</li>
  {/each}
</ul>
```
