Stelve For Loop

Svelte offers us a great each structure for repeatable elements. E.g;

<script>
    let names = ['phpexample', 'jack', 'daniels']
</script>

<ul>
    {#each names as name (name)}
        <li>{name}</li>
    {/each}
</ul>

But what if we had a block that repeated based on the number held in a variable? Svelte does not provide us any convenience regarding the for loop :/ What can we do?

We can perform our operation by creating an array of n with Array(n) and inserting it into each. E.g;

<script>
    let rows = 5
</script>

<ul>
    {#each Array(rows) as _, row (row)}
        <li>{row}. Line</li>
    {/each}
</ul>

this much, good work.

Comments

There are no comments, make the firs comment