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
When I was helping someone adjust the code today,...
The steps for configuring Tomcat in IDEA 2020 are...
Copy code The code is as follows: <!DOCTYPE ht...
Table of contents 1. How to view the binary data ...
This article shares the specific code for JavaScr...
Let me look at the example code first: 1. Common ...
Table of contents 1. Help Command 2. Mirror comma...
Author: Ding Yi Source: https://chengxuzhixin.com...
Table of contents 1. Test experiment 2. Performan...
When setting the text in the search text box, the...
Promise is a new solution for asynchronous progra...
I have encountered many problems in learning Dock...
1. Software Introduction VirtualBox VirtualBox is...
Table of contents Written in front router.json Ro...
Before understanding this problem, let's firs...