The .sort() method sorts the elements of an array. The default method will sort the array according to string Unicode code points. To sort an array numerically the .sort() method needs to have a compareFunction passed to it.
The .sort() method is impure. .sort() will sort the array in-place, i.e., instead of creating a sorted copy of the original array, it will re-order the original array and return it.
Sorts the array in UNICODE order
The uppercase characters have moved above lowercase. The array is not in alphabetical order, and numbers are not in numerical order
The above sort will throw an error if any array items are not a string. If you know that the array may contain items that are not strings use the safe version below.
String sorting by length (longest first)
String sorting by length (shortest first)
Sorting array by even and odd numbers
Date Sort (descending)
"Tue Aug 23 2016 00:00:00 GMT-0600 (MDT)",
"Fri Mar 21 2014 00:00:00 GMT-0600 (MDT)",
"Sat Jul 11 2009 00:00:00 GMT-0600 (MDT)",
"Mon Dec 10 2007 00:00:00 GMT-0700 (MST)"