JS Array creation and concat()split()slice()slice()
1 var a = new Array();2 var b=new Array(20);3 var c= new Array("red","green","white");alert(b.length) //20The array can be increased or decreased as needed. therefore,
c[3] = "purple";alert(c.length) //4
if
c[25]="purple" //Then the positions from 3 to 24 are filled with null alert(c.length) //26
You can also define an Array object with literal representation, that is, use square brackets and separate values with commas.
var d =["red","green","white"];alert(d.length) //3d[25]="purplr"alert(d.length); //26
Note that in this example, the Array class is not explicitly used. Square brackets imply that the values are stored in the Array object. The array declared in this way is the same as the array declared in the traditional way.
The Array object overrides the toString() method and the valueOf() method. Returns a special string.
var e =["red","green","white"];alert(e.toString()); //"red,green,white"alert(e.valueOf()); //Same as above
join()
alert(e.join("-spring-")) //"red-spring-green-spring-white"Split() method, String converts itself into an array
var s="a,b,c";var sS=s.split(",");//Return 3 arraysPer-character parsing string
var s="green"var ss=s.split("")alert(ss.toString()) //Return "g,r,e,e,n"The Array object has two methods that the String class has, namely the concat() and slice() methods; the concat method handles arrays the same way as processing strings. The parameters will be appended at the end of the array, and the returned function value is the new Array object.
The slice() method is the same as String's slice() method. It returns a new array with specific items: if there is only one parameter, the change method will return all items starting from that position to the end of the array; if there are two parameters, it will return all the ideas between the first position and the second bit, excluding the items at the second position
var s=["a","b","c"];var scon=s.concat("d","e");alert(scon.toString()) //"a,b,c,d,e"alert(s.toString()) //"a,b,c"var s1=s.slice(1) //s1 is "b,c" var s2=s.slice(0,2) //s2 is "a,b"The above article "Create" of JS Array and the use of concat()split()slice() is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.