By passing in an optional SortFunction, you can sort numerically and by other criteria as well. If SortFunction is defined, the array elements are sorted based on the relationship between each pair of elements within the array, "a" and "b", and your function's return value. The three possible return numbers are: <0 (less than 0), 0, or >0 (greater than 0): Less than 0: Sort "a" to be a lower index than "b" Zero: "a" and "b" should be considered equal, and no sorting performed.
Greater than 0: Sort "b" to be a lower index than "a". Take a look at the following 3 distinct examples: //Sort Alphabetically and ascending: var myarray=["Bob","Bully","Amy"] myarray.sort() //Array now becomes ["Amy", "Bob", "Bully"] //Sort Alphabetically and descending: var myarray=["Bob","Bully","Amy"] myarray.sort() myarray.reverse() //Array now becomes ["Bully", "Bob", "Amy"]