Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
In Javascript how do you dimension a 12x18 array:

var DESC = new string[12, 18];

What I have tried:

string DESC = new string[12, 18];
Posted
Updated 4-Jul-18 11:06am

Like so:
JavaScript
var array = new Array(12);
for (var i = 0; i < 12; i++) {
  array[i] = new Array(18);
}
 
Share this answer
 
Comments
teledexterus 4-Jul-18 14:09pm    
Will this give me: array[1, 1]="Something";
[no name] 4-Jul-18 14:12pm    
You would assign it like so:
array[1][1] = "Something";
teledexterus 4-Jul-18 14:15pm    
I am getting as error on : var array = new Array(12);
[no name] 4-Jul-18 14:18pm    
What is the error? The syntax is correct, have a look here: http://jsfiddle.net/uo5d8zk9/
The first answer is a perfectly valid answer. Just thought I might add the alternate syntax version:

JavaScript
var ax2 = [12];
for (var i = 0; i < ax2.length; i++) {
  ax2[i] = [18];
}
ax2[0][0] = 23*38;
alert(ax2[0][0]);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900