Array sorting in JavaScript

Source: Internet
Author: User

In JavaScript, an array class is provided with a method Array.Sort () that can be sorted into arrays;

However, this method is sorted by Unicode code, if the integer type is added to the array element,

The result of discharge often does not reach the result we want; If you must use this method, it is best to convert the integer to

The way the string is, and then sort it, can reach the result from small to large;

If you do not convert, you need to create a sort function to complete:

function Arraynumber (A, A,) {return a-B}

And then make the call:

Array.Sort (Arraynumber);

The resulting results will be from the size to the large arrangement;

Array sorting in JavaScript

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.