Sort () Localecompare () sort () uses the sort () function to sort the array objects used, the collation installs the character encoding order, such as: (cannot be directly compared to Chinese) var arr = new Array (6); Arr[0] = "arr[1" = "1" arr[2] = "8" arr[3] = "+" arr[4] = "" "Arr[5" = "1" Arr.sort (), return:1,1,1000,23,25,8, sort by first value sort has one parameter to set collation, Arr.sort (sortnumber), parameter is method name, sort method will arr[i], arr[i+1 in order) The Incoming method Sortnumber (A, A, a, b) is compared by the bubble sort return rule: A is less than B, and a value less than 0 is returned, and sort sorts a before B before a is equal to 0. A is greater than B and returns a value greater than 0, and sort sorts the B before the A
If a is greater than B, a value greater than 0 is returned.
that is, when arr[0], arr[1] is passed in, return a-B, returning 22 is greater than 0, that is, the return value of a appears in front of a
using the collation provided by the underlying operating system,most of the character sets are not in alphabetical order, the availability is not high, GB2312 first-level Chinese character library sorted by Pinyin) such as: A.localecompare (b) If the current string object precedes B, then Localecompare () returns 1, if the current string is after B, 1 is returned, and if two strings are equal, 0 is returned using sort (), Localecompare () sort the first letter of the Chinese array
JS Chinese first alphabetical order (one)