Modern JS
ES2020+2020 – todayYearly, incremental releases. Small operators that erase enormous amounts of defensive boilerplate, plus top-level await for module-scope asynchrony.
`toSorted`, `toReversed`, `toSpliced`, `with`, and `.at` return new arrays instead of mutating in place. Combined with negative indexing, immutable updates become readable and free of the classic copy-then-mutate footgun.
const scores = [80, 30, 55];
const sorted = scores.toSorted((a, b) => a - b);
const reversed = scores.toReversed();
const replaced = scores.with(1, 99);
const cut = scores.toSpliced(0, 2);
console.log("original untouched:", scores);
console.log("toSorted:", sorted);
console.log("toReversed:", reversed);
console.log("with(1, 99):", replaced);
console.log("toSpliced(0, 2):", cut);
console.log("scores.at(-1):", scores.at(-1));
// The old way copied first, then mutated:
const legacy = [...scores].sort((a, b) => a - b);
console.log("legacy copy+sort:", legacy);| V8 | `.at()` in V8 9.2 (2021); the `toSorted`/`toReversed`/`toSpliced`/`with` copy methods in V8 11.4 (2023). |
|---|---|
| Node.js | `.at()` since Node 16.6; the four copy methods since Node 20. |
| Deno | `.at()` in Deno 1.16; the copy methods in Deno 1.34. |
| Bun | The full set has been available since Bun 1.0 via JavaScriptCore. |