Home >Web Front-end >JS Tutorial >How to write two-dimensional array in javascript
How to write two-dimensional arrays in javascript: 1. "var array name = []; a [one-dimensional subscript, two-dimensional subscript] = value;"; 2. "var array name = [[value List],...[List of values]];"; 3. "var array name=new Array([List of values],...[List of values]);".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
JavaScript does not directly support two-dimensional arrays, but you can set the value of the array element equal to the array, so that you can simulate the two-dimensional array structure.
Method 1 to define a two-dimensional array:
var a = []; a[0,0] = 1; a[0,1] = 2; a[1,0] = 3; a[1,1] = 4;
Method 2 to define a two-dimensional array:
var a = [ //定义二维数组 [1.1, 1.2], [2.1, 2.2] ];
Method 3 to define a two-dimensional array:
var a = new Array( [1.1, 1.2], [2.1, 2.2] ); //定义二维数组##[Recommended learning:
javascript advanced tutorial 】
The above is the detailed content of How to write two-dimensional array in javascript. For more information, please follow other related articles on the PHP Chinese website!