Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How JavaScript defines two-dimensional arrays
How JavaScript defines two-dimensional arrays
Method 1:

Define a two-dimensional array with known length, which can be defined and initialized directly.

var _TheArray = [["0- 1 "," 0-2"],[" 1- 1 "," 1-2"],["2- 1 "," 2-2"]]

Method 2:

Defines a two-dimensional array of unknown length.

var? tArray = new? array(); //First declare a one-dimensional array.

for(var? k = 0; K< me; k++)? //The length of one-dimensional array is I, and I is a variable, which can be changed according to the actual situation.

{

tArray[k]=new? array(); ? //Declare two dimensions, and each element in a one-dimensional array is an array.

for(var? j = 0; j & ltp; j++)? //The number p that each element array in a one-dimensional array can contain is also a variable.

{

tArray[k][j]= " 1 "; ? //The variable is initialized here, and it is uniformly initialized to 1 on my side.

}

}

Extended data:

Creation of JavaScript multidimensional array;

& lt script & gt

var? allarray=new? array();

var? res =

Function? loaddata()

{

for(var? I = 0; I<3; i++)

{

var? starth = i * 200?

var? strarw = i * 200

var? endh =(I+ 1)* 200; ?

var? endw =(I+ 1)* 200; ?

allarray[i]=new? array(); ?

allarray[i][0]=new? array(); ?

allarray[i][ 1]=new? array(); ?

all array[I][0][0]= starth; ?

allarray[I][0][ 1]= strarw;

allarray[I][ 1][0]= endh; ?

allarray[I][ 1][ 1]= endw; ?

}

for(var? I = 0; I & ltallarray.lengthi++)

{?

var? sh = all array[I][0][0];

var? sw=allarray[i][0][ 1]

var? eh = all array[I][ 1][0];

var? ew = all array[I][ 1][ 1]

Res+= "The starting coordinate of the coordinate" +i+ "is" +SH+ ",and the ending coordinates of" +SW+ "are" +eh+ "and +ew+".

}?

document.getElementById("dv ")。 innerHTML = res

}

& lt/script & gt; .

MDN web document-array