Home >Web Front-end >JS Tutorial >How to write two-dimensional array in javascript

How to write two-dimensional array in javascript

青灯夜游
青灯夜游Original
2021-10-28 17:59:295923browse

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]);".

How to write two-dimensional array in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Creation of two-dimensional array

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]
];

How to write two-dimensional array in javascript

Method 3 to define a two-dimensional array:

var a = new Array(
[1.1, 1.2],
[2.1, 2.2]
);  //定义二维数组

How to write two-dimensional array in javascript

##[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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn