Home >Web Front-end >JS Tutorial >How to output a two-dimensional array with 4 rows and 3 columns in JavaScript

How to output a two-dimensional array with 4 rows and 3 columns in JavaScript

青灯夜游
青灯夜游Original
2021-10-28 16:01:123945browse

In JavaScript, you can use a double-layer for loop and write() to output a two-dimensional array with 4 rows and 3 columns. The syntax is "for(var i=0;i

How to output a two-dimensional array with 4 rows and 3 columns in JavaScript

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

JavaScript outputs a two-dimensional array with 4 rows and 3 columns

Here is a two-dimensional array with 4 rows and 3 columns:

var a = [  //定义二维数组
    [1.1, 1.2, 1.3, 1.4],
    [2.1, 2.2, 2.3, 2.4],
    [3.1, 3.2, 3.3, 3.4]
];

Let’s take a look at how to output:

Method: Use a double-layer for loop

The outer for loop controls the number of rows, and the memory for Loop control column number

Implementation code:

<script type="text/javascript">
var a = [  //定义二维数组
    [1.1, 1.2, 1.3, 1.4],
    [2.1, 2.2, 2.3, 2.4],
    [3.1, 3.2, 3.3, 3.4]
];
	for(var i=0;i<=4;i++){
		for(var j=0;j<=3;j++){
			document.write(a[i][j]+"  ");
		}
		document.write("<br>");
	}
</script>

Output result:

How to output a two-dimensional array with 4 rows and 3 columns in JavaScript

[Recommended learning :javascript advanced tutorial

The above is the detailed content of How to output a two-dimensional array with 4 rows and 3 columns 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