Skip to content

Commit 1a25b97

Browse files
committed
Update 03-each.md
1 parent 1dea056 commit 1a25b97

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

documentation/docs/03-template-syntax/03-each.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ title: {#each ...}
1212
{#each expression as name, index}...{/each}
1313
```
1414

15-
Iterating over values can be done with an each block. The values in question can be arrays, array-like objects (i.e. anything with a `length` property), or iterables like `Map` and `Set` — in other words, anything that can be used with `Array.from`. For reactive values, changes in state are determined by comparing old and new items at the same position in the iterated sequence. As such, an "unkeyed" each block is best suited for values whose length stays fixed, since a change in position of an item will cause a change in state.
15+
Iterating over values can be done with an each block. The values in question can be arrays, array-like objects (i.e. anything with a `length` property), or iterables like `Map` and `Set` — in other words, anything that can be used with `Array.from`. For reactive values, changes in state are determined by comparing old and new items at the same index in the iterated sequence. As such, an "unkeyed" each block is best suited for values whose length stays fixed, since changes in positions of items will be interpreted as changes in state.
1616

1717
```svelte
1818
<h1>Shopping list</h1>
@@ -43,7 +43,7 @@ An each block can also specify an _index_, equivalent to the second argument in
4343
{#each expression as name, index (key)}...{/each}
4444
```
4545

46-
If a _key_ expression is provided — which must uniquely identify each iterated item — Svelte will compare old and new reactive items having the same key to determine state changes, rather than comparing items at the same position in the iterated sequence. This is useful when the positions of items change, e.g. when modifying the length of an array. The key can be any object, but strings and numbers are recommended since they allow identity to persist when the objects themselves change.
46+
If a _key_ expression is provided — which must uniquely identify each iterated item — Svelte will compare old and new reactive items having the same key (instead of the same index) to determine state changes. This is useful when the positions of items change, e.g. when modifying the length of an array. The key can be any object, but strings and numbers are recommended since they allow identity to persist when the objects themselves change.
4747

4848
```svelte
4949
{#each items as item (item.id)}

0 commit comments

Comments
 (0)