JS Chinese first alphabetical order (one)

Source: Internet
Author: User
Tags sorts

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.