Usage:
(1) array. Sort() // The default sort is to sort alphabetically by strings. If the elements are numbers, they will also be sorted as strings.
(2) array. Sort// Sort parameters are used for sorting, and the sorting method is some defined integer constants.
(3) array. Sort//Use a user-defined comparison function. Note that only function sorting can be written here.
SortOn is used when array elements are complex data types and need to be sorted according to the attribute values of such objects. For example, an element has an attribute value name, and you want to sort it by name, then the method used is as follows.
Usage:
(1) array. SortOn("name") // Sort by default according to the specified attribute.
(2) array. SortOn("name ",sorting method)//Sort by using the specified" sorting method "according to the specified attribute.
(3) array. SortOn("name ",comparison function)//Sort by using a user-defined function according to the specified attribute.
Sorting methods refer to some plastic constants defined in the Array class, which represent several different sorting methods.
The value of the (1) array. Case-insensitive is 1, which means case-insensitive and sorted alphabetically. If it is a number, it is from small to large.
(2)2) Values of the array. The descending order is 2, which means sorting alphabetically.
(3)3) Values of the array. UNIQUESORT is 4, which means it must be a unique sort. If the comparison results are the same, the sorting is abandoned and the return value is 0.
(4) the value of the array. RETURNINDEXEDARRAY is 8, so that the return values of the sort () and sortOn () functions can be returned to the sorted index list, while keeping the original array unchanged.
(5) the value of the array. Numeric or 16 is 16, and the values in sort () and sortOn () are forced to be sorted from small to large.
The comparison function requires two parameters, and the return value is one of 1, 0 and-1.