The JavaScript has a method sort()
for sorting array elements in ascending order, i.e. the sorting will result into lowest to highest. For alphabetic values, the sorting will be according to the alphabetical series, the alphabet which comes first in the alphabetical series will be sorted first. Same for the numbers series, the lowest number will be sorted first and then the number bigger than the previous one and so on.
If both numbers and alphabets are present in the values then, first the alphabets will get sorted and then the numbers, like, Code, 15, Html, 20, 65
will be sorted as Code, Html, 15, 20, 65
.
The reverse()
method is used to reverse the order of the elements of an array i.e. the first array element becomes the last, and the last array element becomes the first. Here, the sorting is not based on the ascending or descending orderering of the elements. Whatever the order of element is, reverse sorting will just reverse the order and nothing else.
Follow Us: