The following small series is a simple introduction to reverse (), sort (), concat (), slice (), splice () method in the array. Come and have a look.
The code is as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml "> <head> <title> reordering method and operation method </title > <script type= "Text/javascript" > //Sort method function Basicsort () { var values=[0,10,2,3,12,5]; alert (values . reverse ()); the//reverse () method simply turns the order of the array in turn alert (Values.sort ()), and the//sort () method compares the strings. Most cases are not the best scenario alert (Values.sort (Compare));//sort () method can receive a comparison function as a parameter } //Custom comparison functions, the returned array is ascending, or you can change the code, such as Value1<value2 return 1, to achieve the result is descending. Function compare (value1,value2) { if (value1 < value2) { &N Bsp return-1; }eLSE if (Value1 > value2) { return 1; }else{ & nbsp return 0; } { //action method The Concat () method creates a new array based on all the items in the current array &nb Sp Function Basicconcat () { var colors=["Red", "Blue", "pink"]; & nbsp var colors2=colors.concat ("Yellow", ["Black", "Brown"]);//red,blue,pink,yellow,black,brown Alert (COLORS2); } /The method is to create a new array based on all the items in the current array and receive one or two parameters, that is, intercept end > str >=start (That is, items that do not include the end position) function Basicslice () { var colors=["Red", "Blue", "pink "," Yello "," White "]; var colors2=colors.slice (1); var colors3=colors.slice (1,4); alert (COLORS2); alert (COLORS3); } function Basicsplice () { var colors=[" Red "," Blue "," Pink "," Yello "," White "]; var removed=colors.splice (0,2)//table deletion is deleted the first two alert ("delete Items: "+removed+"----Current items: "+colors" var Inserted=colors.splice (1,0, "Black", "gray"); Indicates deletion of 0 items at location 1, insert new add alert ("Current item:" +colors); } </script> </head> <body> <input type= "button" Valu E= "sorted sort" onclick= "basicsort ();"/> <input type= "button" value= "Concat" onclick= "Basicconcat ();"/> & nbsp <input type= "button" value= "Slice" onclick= "basicslice ();"/> <input type= "button" value= "Splice" Onclick= "Basicsplice ();"/> </body> </html>