Complete the code to create a keyed each block that uses the item's id as the key.
<script>
let items = [{ id: 1, name: 'Apple' }, { id: 2, name: 'Banana' }];
</script>
<ul>
{#each items as item ([1])}
<li>{item.name}</li>
{/each}
</ul>The key in a keyed each block should be a unique identifier for each item. Here, item.id is used as the key.
Complete the code to update the list with a keyed each block using the correct key.
<script>
let fruits = [
{ id: 'a1', name: 'Mango' },
{ id: 'b2', name: 'Peach' }
];
</script>
<ul>
{#each fruits as fruit ([1])}
<li>{fruit.name}</li>
{/each}
</ul>The key must be a unique identifier for each fruit. fruit.id is the correct key.
Fix the error in the keyed each block by choosing the correct key.
<script>
let tasks = [
{ id: 101, title: 'Clean room' },
{ id: 102, title: 'Do laundry' }
];
</script>
<ul>
{#each tasks as task ([1])}
<li>{task.title}</li>
{/each}
</ul>The key must be a unique identifier for each task. task.id is the correct key to fix the error.
Fill both blanks to create a keyed each block that uses the correct key and variable names.
<script>
let users = [
{ uid: 1, username: 'alice' },
{ uid: 2, username: 'bob' }
];
</script>
<ul>
{#each users as [1] ([2])}
<li>{username}</li>
{/each}
</ul>users as the variable name.uid without the variable name as the key.The variable name inside the each block should be user. The key should be user.uid to uniquely identify each user.
Fill all three blanks to create a keyed each block that uses the correct variable, key, and displays the username.
<script>
let members = [
{ id: 10, username: 'charlie' },
{ id: 20, username: 'diana' }
];
</script>
<ul>
{#each members as [1] ([2])}
<li>[3]</li>
{/each}
</ul>members as the variable name.The variable name should be member. The key should be the unique id property. The displayed value should be member.username.