Array segmentation in javascript var colors = ["Red", "green", "blue"];
Alert (colors.tostring ()); Alert (Colors.join ("|"));
The return result is red|green|blue var colors = ["Red", "green", "blue", null]; Alert (Colors.join ("|"));
/red|green|blue| Note that when the value in the array is null or undefined, the result returned is an empty string representing-------------------------------------------//array deletion and adding var colors = ["
Red "," green "," blue "];
Alert (colors.tostring ()); Colors.push ("White", "test");//The result returned is the length of the array alert (Colors.join ("|"));
/The result is red|green|blue|white|test//add element var colors to the beginning of the array = ["Red", "green", "Blue", "test"]; var item = colors.unshift ("First");//The beginning of the array adds an element alert (Colors.join ("|"));
/return the last array//delete element var colors = ["Red", "green", "Blue", "test"]; var item = Colors.pop ()//Returns the deleted option result test alert (Colors.join ("|"));
/returns the final array result red|green|blue//delete the opening element var colors = ["Red", "green", "Blue", "test"]; var item = Colors.shift ();//Deletes the first option alert (Colors.join ("|") of the array); /returns the last array-------------------------------------------------//array sequence case//order reversal var colors = ["Red", "green", "Blue", "test"]
;Colors.reverse ();
alert (colors);//The result is: test,blue,green,red//array sort var values = [0,1,5,10,7];
Values.sort (Compare);
alert (values);
Document.writeln (values);
} function Compare (value1,value2) {if (value1<value2) {return 1;
}else if (value1>value2) {return-1;
}else return 0;
-----------------------------------------------------//Add array to array concat () method var colors = ["Color", "red"];
var colors2 = Colors.concat (["CCC", "BBBB"], ' 3333 ', [' vvccxx ', [' oolll ', ' lll ']]; alert (colors2);//Returns the result is: Color,red,ccc,bbbb,3333,vvccxx,oolll,lll//slice () method copying elements in an array does not break the previous element var colors = ["Color"
, "Red", ' eeee ', ' 221111 ']; var colors2 = Colors.slice (1);//Starting from 1 Replication alert (colors2);//The result is: red,eeee,221111 var colors = ["Color", "red", ' eeee ', '
221111 ']; var colors2 = Colors.slice (1,3);//Copy from 1 to 3rd position end alert (colors2);/The result is red,eeee-----------------------------------
----------------------------------//Array Delete element var a = [1,2,3,5,8]; var r = a.splice (0,2);
Delete the top 2 alert (a);//The result is 3,5,8 var a = [1,2,3,5,8]; VAr r = a.splice (1,1,100,200); Deletes an item starting at number 2nd and then inserts alert (a); the result is 1,100,200,3,5,8.