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