Sort can automatically arrange items in an array. In this lesson we look at the basics including how to sort an array of strings alphabetically and the correct way to perform a numerical sort on an array of numbers. We finish as always with a practical use-case that shows not only sort
in action, but also how it can be chained together with other array methods such as map
and join
.
It is a pity that we are destroying our original list in this way. It would be nicer if "sort" as well as "map" created a new list.