JavaScript Learning Notes (authoritative guide)

Source: Internet
Author: User

1, the array of the sort () method is alphabetically sorted by default, the following is a chestnut description:
1) All the letters:

var arr =["zu", "Fan", "an", "Peng", "Zhang"];arr.sort (); alert (arr);//result is An,fan,peng,zhang,zu

2) are all numbers:

var arr =["", "" "", "" "", "" 668 "];arr.sort (); alert (arr);//result is 12,34,44,668,67

3) Alpha-numeric combination:

var arr =["A2", "5", "Y7", "6k"];arr.sort (); alert (arr); //result is 34,5,6k,a2,y7 (display sorted by number, then in alphabetical order)

4) the sort () method can be ordered in ascending (descending) Order of the array:

var arr =["", "" "," "", "" "668 "
Arr.sort (function
  return A- C; (if replaced with b-a, it is in descending order)

JavaScript Learning Notes (authoritative guide)

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.