Skip to content

Glossary: JavaScript Basics

sort / toSorted

Also written: sort, toSorted, reverse

`sort` puts an array in order by changing it, comparing as strings unless you pass a compare function. `toSorted` takes the same function but returns a sorted copy and leaves the original alone.

Where the book teaches it

Related terms

Compare functionlocaleCompare