sort() changes the array in place, which bites you when something else still uses it.
const names = ["Eva", "Bram", "Anouk"];
const sorted = names.toSorted();
// sorted: ["Anouk", "Bram", "Eva"]
// names: ["Eva", "Bram", "Anouk"]
There are matching toReversed() and toSpliced(). They are in current browsers and in Node 20 and later, so check your target before you use them. Like sort(), the default sorts as text, so numbers need a compare function.
Further reading: Array.prototype.toSorted on MDN