Svelte 3 - How to loop each block X amount of times
i Use like this for travelling from a
to b
in Svelte
{#each Array.from(Array(b+1).keys()).slice(a) as i }
<h1>{i}</h1>
{/each}
example (1 to 100):
{#each Array.from(Array(100+1).keys()).slice(1) as i }
<h1>{i}</h1>
{/each}
You can use {#each ...}
, like:
{#each Array(3) as _, i}
<li>{i + 1}</li>
{/each}
An #each
tag can loop anything with a length property, so:
{#each {length: 3} as _, i}
<li>{i + 1}</li>
{/each}
will also work, if you prefer.