Need a sorted array without changing the order of the original? `toSorted` works like `sort`, but returns a sorted copy instead of modifying the array it was called on. section 10.1.4
Keep the original order
`const numbers = [3, 1, 2]; const sorted = numbers.toSorted((a, b) => a - b);` Now `sorted` is `[1, 2, 3]`, while `numbers` remains `[3, 1, 2]`. section 10.1.4
The distinction matters when assigning the result: `const sorted = numbers.sort(...)` does not preserve `numbers`. `sort` modifies the original array and returns that same array. Before `toSorted`, the usual workaround was to duplicate the array, then sort the duplicate. `toSorted` provides that non-mutating choice directly. section 10.1.4
