concat array of reverse sort method

. 1  <! DOCTYPE HTML > 
2  < HTML > 
. 3      < head > 
. 4          < Meta charset = "UTF-. 8" > 
. 5          < title > </ title > 
. 6      < Script type = "text / JavaScript" > 
. 7     / * 
. 8     the concat ( )
 9     connected to two or more arrays, and returns the array
 10     which does not affect the original array
 . 11     * / 
12 is    var A = [ . 1 , 2 , . 3 ];
13 is    var B = [ 2 , . 4 , . 6 ];
 14    the console.log (a.concat (B));
 15    / * 
16    the Join ()
 . 17    The method may be converted to a string array
 18    made, this method does not impact on the original array, but the converted string returned as a result
 19    can be specified as a parameter in a string join (), this will be connected to the string value in the descriptor elements
 20 is    * / 
21 is   var result = a.join ( " $$ " );
 22 is  the console.log (Result);
 23 is   / * 
24  reverse ()
 25  inverted array
 26  which directly modify the original array of
 27  
28  Sort ()
 29  can be used to sort the elements of the array
 30  will be in the original array, it is sorted by default Unicode encoded
 31  so for digital sort is not possible to obtain results in ascending / descending order of
 32   
33 is  possible to specify their own ordering rules
 34  we can add a callback function sort (), to specify a collation
 35     requires two parameters define the callback function
 36     browser will use each element in the array as an argument to the callback function
 37     used which call uncertain element, but certainly is in constant b in front of the array a
 38 is    sequentially browser to determine the value of the element according to the callback function returns,
 39    value of greater than 0 if the return, the position of the switching element will be
 40    if the return a value less than 0, the element position constant
 41    if returns 0, that two equal elements, without exchanging the position
 42 is   * / 
43 is  var ARR = [ . 4 , . 5 ];
 44 is arr.sort(function(a,b){
45     /*
46     //前面的大
47     if(a>b)return 1;
48     else if(a<b)return -1;
49     else return 0;
50     */
51    return a-b;//升序
52 });
53     </script>
54     </head>
55     <body>
56     </body>
57 </html>

 

Guess you like

Origin www.cnblogs.com/zuiaimiusi/p/11224996.html