The method for sorting arrays is called.. sort
!.
Default sort
1var fruit = ['cherries', 'apples', 'bananas'];
2fruit.sort(); // ['apples', 'bananas', 'cherries']
3
4var scores = [1, 10, 21, 2];
5scores.sort(); // [1, 10, 2, 21]
6// Watch out that 10 comes before 2,
7// because '10' comes before '2' in Unicode code point order.
8
9var things = ['word', 'Word', '1 Word', '2 Words'];
10things.sort(); // ['1 Word', '2 Words', 'Word', 'word']
11// In Unicode, numbers come before upper case letters,
12// which come before lower case letters.
sort
to sort both objects and arrays (because: arrays are objects..)obj[param]
instead of obj.param
or obj['param']
.