Home >Web Front-end >JS Tutorial >JavaScript implements multidimensional array
In C#, defining a multi-dimensional array can be achieved through such a simple code:
[csharp]
int[,]myArray=new int[4,5];
In JavaScript, multi-dimensional arrays cannot be implemented through direct definition, then How to achieve this?
First define a one-dimensional array:
[javascript]
var myArray=new Array();
Then define the members of the one-dimensional array as an array (redefinition is possible because JavaScript is weakly typed):
[javascript ]
myArray[0]=new Array();
So far, a two-dimensional array with the first index of 0 has been defined. If you want to use the first two-dimensional array with index of 1, you must still Need to be defined:
[javascript]
myArray[1]=new Array();
The following is an example of JavaScript multi-dimensional array application , the implementation is to use multi-dimensional arrays to store the questions and answers of multiple-choice questions:
[javascript]