1. Declaration method of array
(1): arrayObj = new Array(); //Create an array.
The code is as follows:
var arr1 = new Array();
(2): arrayObj = new Array([size]) Create an array and specify the length, note that it is not the upper limit, it is the length.
The code is as follows:
var a = new Array(5);
(3): arrayObj = new Array([element0[, element1[, ...[, elementN]]]]) Create an array and assign a value.
The code is as follows:
var a = new Array(["b", 2, "a", 4,]);
(4): arrayObj = [element0, element1, ..., elementN] Create an array and assign values. Note that the brackets here do not mean that they can be omitted.
The code is as follows:
var a = ["b", 2, "a", 4,];
(Note): Pay attention to the difference between "[]" and "[]" without "[]"
The code is as follows:
var a = new Array(5); //Refers to creating an array of length 5 var a = new Array([5]); //Refers to creating an array with length 1 and the first bit is 5
2. Common methods of arrays
3.Array operation (transmit address)
The code is as follows:
var t2=new Array();t2[0]=1;t2[1]=2;test2(t2); //Pass address (array) function test2(var2) {for(var i=0;ivar2[i]=var2[i]+1;}}for(var i=0;ialert(t2[i]);}The above simple method to create arrays by js 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.