This article mainly introduces how to sort JavaScript object arrays. it analyzes the sorting principle and related skills of JavaScript object arrays in the form of examples and has some reference value, for more information about how to sort JavaScript object arrays, see the following example. We will share this with you for your reference. The details are as follows:
The sort method of the array sorting function in javascript. by default, the sorting is performed in ascending order of ASCII characters.
Arrayobj. sort (sortfunction );
Parameter: sortFunction
Optional. Is the name of the function used to determine the order of elements. If this parameter is omitted, the elements are listed in ascending order of ASCII characters.
The sort method sorts Array objects appropriately. during execution, no new Array objects are created.
If a function is provided for the sortfunction parameter, the function must return one of the following values:
Negative value if the first parameter is smaller than the second parameter.
Zero. if the two parameters are equal.
If the first parameter is greater than the second parameter.
The preceding method is very convenient in one-dimensional sorting, but how does one sort multiple key values like order by in SQL statements?
Multi-dimensional array multi-key value sorting requires complexity, but does not need to be solved cyclically. The actual solution is the same.
Number:
In the following example, the multi-dimensional array of numbers is sorted in the ORDER of 5th columns, 9th columns, and 3rd columns, such as order by col5, col9, col7 in SQL statements. You can subtract two items directly, and use the result as the return value.