# Sorting Arrays

sort puts an array in order, but it compares items as text unless you give it a compare function, and it changes the array itself, so toSorted is the way to get a sorted copy and keep the original.

![Cheat sheet: Sorting Arrays](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/10/0d7bb6120e7a4deda9aac99ede578e36.webp)

- Category: JavaScript
- Level: Apprentice
- Tags: Compare Function (javascript), Immutability, JavaScript, slice(), sort() (javascript), toSorted() (javascript)
- Updated: November 1, 2026

Source: https://www.ask-codey.com/cheat-sheets/javascript-array-methods-sort-cheat-sheet
