Javascript array sorting function _ javascript skills

Source: Internet
Author: User
Tags javascript array
The sort method of the array sorting function in javascript. By default, the sorting is performed in ascending order of ASCII characters. Arrayobj. sort (sortfunction );
Parameter: sortFunction
Optional. Is the name of the function used to determine the order of elements. If this parameter is omitted, the elements are listed in ascending order of ASCII characters.
The sort method sorts Array objects appropriately. During execution, no new Array objects are created.
If a function is provided for the sortfunction parameter, the function must return one of the following values:
Negative value if the first parameter is smaller than the second parameter.
Zero. If the two parameters are equal.
If the first parameter is greater than the second parameter.
The preceding method is very convenient in one-dimensional sorting, but how does one sort multiple key values like order by in SQL statements?
Multi-dimensional array multi-key value sorting requires complexity, but does not need to be solved cyclically. The actual solution is the same.
Number:
In the following example, the multi-dimensional array of numbers is sorted in the ORDER of 5th columns, 9th columns, and 3rd columns, such as order by col5, col9, col7 in SQL statements. You can subtract two items directly, and use the result as the return value.

The Code is as follows:


Related Article

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.