For example, VAR arr = ["中"", "", "and", ""], after executing the sort method, the result is: the sorting of Chinese characters, Chinese characters, and Chinese characters is neither pinyin nor the number of strokes.
I have seldom noticed the localecompare method before. In the manual, a value is returned when it is executed, indicating whether two strings are the same in the current region settings. There are three return values:-, 1, which is exactly the type required by the sort method parameter. Apply localecompare to the sort method and check the result:
VaR arr = ["中"", "", "and", ""];
Alert (ARR. sort (function (a, B) {return. localecompare (B)}); // The result is: total, country, and, Hua, Min, man, medium (pinyin ascending)
Note that the localecompare method is compared in the current region, that is, the compare environment is the geographic region set by the current operating system, for example, the expression of numbers, currencies, date and time (you can view and modify them in the control panel). If you set the sorting method to stroke, the above result will be: person, china, the people, the Communist Party of China, and the State (in ascending order of strokes ).