A guide to the 4 new Array.prototype methods in JavaScript
Blog post from LogRocket
ECMAScript 2023, the latest version of the JavaScript language standard, introduces four new array methods—`toReversed()`, `toSorted()`, `toSpliced()`, and `with()`—that focus on non-mutating operations by returning new arrays instead of altering the original ones. These methods cater to a declarative, functional programming style by ensuring pure functions, predictable state management, and simplified change detection in frameworks like React. `toReversed()` and `toSorted()` offer non-mutating alternatives to `reverse()` and `sort()`, handling sparse arrays by returning undefined for empty slots, while `toSpliced()` and `with()` provide non-mutating counterparts to `splice()` and bracket notation for index modification, ensuring original arrays remain unchanged. These methods can also be used with array-like objects, expanding their utility in JavaScript programming.