Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
ES2023 adds four new methods that return new arrays instead of modifying the original!toSorted(),toReversed(),toSpliced(), andwith() are the immutable versions of existing methods!
Immutable version of sort()
Immutable version of reverse()
Immutable version of splice()
Change one element immutably
Sort and reverse without mutating
Modify arrays immutably
| Mutable (Old) | â | Immutable (New) |
|---|---|---|
sort() | â | toSorted() |
reverse() | â | toReversed() |
splice() | â | toSpliced() |
arr[i] = x | â | with(i, x) |
All four methods return new arrays
Original array never modified
Perfect for state updates in React
Latest immutability features