Creation of a two-dimensional array in Js:First of all, JavaScript only supports one-dimensional arrays, but we can implement matrices and multidimensional arrays through some methods. There are no problems with the normal creation method: (1) Create a two-dimensional array by nesting a one-dimensional array: let arr = [] ; a[0] = [1,2,3,4,5,6]; a[1] = [10,20,30,40,50,60] Then use a double for loop to iterate over the elements in this two-dimensional array So using this method to create a multidimensional array, no matter how many dimensions there are, you can traverse it through nested loops Methods for encountering problems:let arr1 = new Array(10).fill(new Array(10).fill(0)) The console prints At this time, if you want to set reason:In summary, it is better to choose an honest creation method: var a = new Array(); for(var i=0;i<5;i++){ //The length of one dimension is 5 a[i] = new Array(); for(var j=0;j<5;j++){ //The length of the two-dimensional is 5 a[i][j] = 0; } } This is the end of this article about the creation techniques of two-dimensional arrays in JavaScript. For more relevant JavaScript two-dimensional array content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL efficient query left join and group by (plus index)
>>: How to submit a pure HTML page, pass parameters, and verify identity
A master once said that you should know the datab...
useState useState adds some internal state to a c...
What are Routing and Routing Table in Linux? The ...
Business social networking site LinkedIn recently...
Problem: The PHP program on one server cannot con...
<br />Structure and hierarchy reduce complex...
Table of contents 1. Introduction 1. Component da...
A few days ago, a colleague asked me a question a...
This article will introduce a very interesting at...
The GtkTreeView component is an advanced componen...
The database, like the operating system, is a sha...
Recently, I have used React Hooks in combination ...
Table of contents 1. Effect Demonstration 2. Impl...
1. Basic usage examples of float 1. Let's fir...
In JavaScript, use the removeAttribute() method o...