Complete the code to loop over the items array and display each item.
<ul>
{#each [1] as item}
<li>{item}</li>
{/each}
</ul>The {#each} block loops over the array named items. You must put the array name after {#each.
Complete the code to include the index of each item in the loop.
<ul>
{#each items as item, [1]
<li>{index}: {item}</li>
{/each}
</ul>The second variable after as item, is the index of the current item in the array. It is commonly named index.
Fix the error in the each block syntax to correctly loop over tasks.
{#each tasks [1] task}
<p>{task.name}</p>
{/each}in or of instead of as.The correct syntax for Svelte each blocks is {#each array as item}. The keyword as is required.
Fill both blanks to loop over users and get both the user and their index.
{#each [1] as [2], idx}
<p>{idx + 1}. {user}</p>
{/each}The first blank is the array users. The second blank is the variable name for each user, user.
Fill all three blanks to create an each block that loops over products, gets each product, and its index.
{#each [1] as [2], [3]
<div>{index}: {product.name}</div>
{/each}The array is products. The item variable is product. The index variable is index.