Skip to content

Commit 104b94e

Browse files
authored
update Modifying values in arrays / Appending new values simplify.
current ```Appending new values To append a new element to an array within a store, you specify the target array and set the index to the desired position. For example, if you wanted to append the new element to the end of the array, you would set the index to array.length: ``` this phrasing may be a little ambiguous, the example for appending, using the path syntax, will always use the array.length to append a value. > and set the index to the desired position may imply to readers that read this section without prior context that the index can be used as insertion point in the array. not realizing that only works with non existing index such as the length, or higher index
1 parent 0dc809b commit 104b94e

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/routes/concepts/stores.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ Instead of relying on discovering individual indices, path syntax introduces sev
253253

254254
### Appending new values
255255

256-
To append a new element to an array within a store, you specify the target array and set the index to the desired position.
257-
For example, if you wanted to append the new element to the end of the array, you would set the index to `array.length`:
256+
To append values to an array in a store, use the setter function with the spread operator to return a new array that includes the new elements. For appending a single element, you can instead leverage the "path syntax" by specifying the array’s length as the index to set.
258257

259258
```jsx
260259
setStore("users", (otherUsers) => [

0 commit comments

Comments
 (0)