From edeeb05a6cd2130755cd47a7aa309c95f1124ce4 Mon Sep 17 00:00:00 2001 From: MichalBednarczyk <48881661+majkelbed@users.noreply.github.com> Date: Wed, 29 Apr 2020 21:48:45 +0200 Subject: [PATCH] docs: {#each} with key but without index (#4721) --- site/content/docs/02-template-syntax.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/site/content/docs/02-template-syntax.md b/site/content/docs/02-template-syntax.md index 3ee5b1dad152..165dd8610617 100644 --- a/site/content/docs/02-template-syntax.md +++ b/site/content/docs/02-template-syntax.md @@ -206,6 +206,9 @@ Additional conditions can be added with `{:else if expression}`, optionally endi {#each expression as name, index}...{/each} ``` ```sv +{#each expression as name (key)}...{/each} +``` +```sv {#each expression as name, index (key)}...{/each} ``` ```sv @@ -242,6 +245,11 @@ An each block can also specify an *index*, equivalent to the second argument in If a *key* expression is provided — which must uniquely identify each list item — Svelte will use it to diff the list when data changes, rather than adding or removing items at the end. The key can be any object, but strings and numbers are recommended since they allow identity to persist when the objects themselves change. ```html +{#each items as item (item.id)} +
  • {item.name} x {item.qty}
  • +{/each} + + {#each items as item, i (item.id)}
  • {i + 1}: {item.name} x {item.qty}
  • {/each}