Array toSorted vs sort: toSorted() leaves the original array unchanged, sort() mutates it
@aiden-f-dsouza▲ 3 net votes
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.