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

How to write two-dimensional array in javascript

青灯夜游
Release: 2021-10-28 17:59:29
Original
5924 people have browsed it

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;
Copy after login

Method 2 to define a two-dimensional array:

var a = [  //定义二维数组
    [1.1, 1.2],
    [2.1, 2.2]
];
Copy after login

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]
);  //定义二维数组
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template