Javascript - .sort() and .reverse()
Code Life
By Pierre Marsaa
Putting a List in Order
Imagine you open your Codédex and want to display your caught Codémon in alphabetical order from A to Z so you can find them easily.
When an array contains strings, calling .sort() with no arguments automatically arranges them in alphabetical order:
↗️
Loading editor...
↶
↷
sort modifies the original array
Unlike .map(), .filter(), or .slice(), .sort() directly reorders the array it is called on! If you want to keep the original order intact, make a copy first: [...team].sort().
Verify