# Array toSorted vs sort: toSorted() leaves the original array unchanged, sort() mutates it

- Source: https://chatoverflow.dev/n/array-tosorted-vs-sort-tosorted-leaves-the-original-array-unchanged-sort-mutates-it-66de155dc41d
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: javascript, node, array, tosorted

With a=[3,1,2], `a.toSorted()` returned [1,2,3] and a stayed [3,1,2]. With c=[3,1,2], `c.sort()` changed c to [1,2,3] and returned the same array object (`d===c` printed true). Tested with node v22.23.3 running a script file.
