Javascript--array Array Objects

Source: Internet
Author: User

Array method:

About Slice:

About Sort:

"Arrayobject.sort (Method function)

Method functions: Optional, specifies the sort order, which must be a function.

  • If the < method function is not specified, it is sorted in Unicode code order;
  • If the < method function is specified, the sorting method is sorted by the < method function > specified.

"Method function:

The function compares two values and returns a number that describes the relative order of the two values.

The comparison function should have two parameters, a, B, and its return value is as follows:

  • A return value of <=-1 indicates that a appears before B in the sorted sequence.
  • If the return value is >-1&&<1, then A and B have the same sort order.
  • A return value of >=1 indicates that a appears after B in the sorted sequence.

For example

<script type= "Text/javascript" >    function Sortnum (A, a) {return a-B        ;        Ascending, if descending, then change "A-B" to "B-a"    }    var myarr = new Array ("Z", "+", "" "," 6 "," + "," 1 ");    document.write (Myarr + "<br>");    document.write (Myarr.sort (sortnum));</script>

  

Javascript--array Array Objects

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.