Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/content/learn/updating-arrays-in-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ Here is a reference table of common array operations. When dealing with arrays i

| | avoid (mutates the array) | prefer (returns a new array) |
| --------- | ----------------------------------- | ------------------------------------------------------------------- |
| adding | `push`, `unshift` | `concat`, `[...arr]` spread syntax ([example](#adding-to-an-array)) |
| removing | `pop`, `shift`, `splice` | `filter`, `slice` ([example](#removing-from-an-array)) |
| replacing | `splice`, `arr[i] = ...` assignment | `map` ([example](#replacing-items-in-an-array)) |
| sorting | `reverse`, `sort` | copy the array first ([example](#making-other-changes-to-an-array)) |

| removing | `pop`, `shift`, `splice` | `toSpliced`, `filter`, `slice` ([example](#removing-from-an-array)) |
| replacing | `splice`, `arr[i] = ...` assignment | `with`, `map` ([example](#replacing-items-in-an-array)) |
| sorting | `reverse`, `sort` | `toReversed`, `toSorted`, or copy the array first ([example](#making-other-changes-to-an-array)) |
Alternatively, you can [use Immer](#write-concise-update-logic-with-immer) which lets you use methods from both columns.

<Pitfall>
Expand Down
Loading