@sniperman
Part One:
To answer your question in slightly more general terms, Vic is right when he types in his second example:
Code:
var array = [[],['b','c'],[],[],[],[]];
That's the proper way to create a multidimensional array.
One could also do it like so:
Code:
var array = [];
array[0] = [];
array[1] = ['b','c'];
array[2] = [];
array[3] = [];
array[4] = [];
array[5] = [];
That makes the same exact array. The reason to avoid the new Array() constructor is that might confuse the script parser later in certain circumstances when making inquiries about the array produced. And it's more expensive visa vis processing time.
What he then does with it might be a little misleading. He takes the second element (array[1]), which is itself an array:
and transforms it into:
so the base array (array) now equals:
Code:
[[],[0,1,2,3],[],[],[],[]]
Part Two:
So let's say you want to make an array with one element that contains an array of six elements, all basically empty like you do here:
Code:
var array = new Array([' ', ' ', ' ', ' ', ' ', ' ']);
That should be:
Code:
var array = [[' ', ' ', ' ', ' ', ' ', ' ']];
but either way var array is a multidimensional array with a length of 1 and array[0] is a simple array with a length of 6, each of its elements is a a string containing one space. This could be expressed as you did like:
array[0][0]
array[0][1]
array[0][2]
array[0][3]
array[0][4]
array[0][5]
Notice I used no code, it's just a quote because it isn't really code. It does describe the structure of the array, but not the value of any of its contents
When you then go:
Code:
for(i=0;i<10;i++)
{
array[i] = new Array([' ', ' ', ' ', ' ', ' ', ' ']);
}
You are for each of the numbers 0 through 9 making a new multidimensional array and assigning it as a value for each of the elements of the previously declared array (var array). If array[i] exists, it's overwritten. If not, it's created. So you don't only get, and perhaps not at all (in your notation):
array[0][0][0]
array[0][0][1]
array[0][0][2]
array[0][0][3]
array[0][0][4]
array[0][0][5]
I'd find it hard to describe in any notation what you would have. But suffice it to say that var array now has a length of 10. So if the above notation is correct, you would also have a:
array[
1][0][0]
array[
1][0][1]
array[
1][0][2]
array[
1][0][3]
array[
1][0][4]
array[
1][0][5]
and so on up to and including 9.
What you would have is the same as if you started over and just did:
Code:
var array = [];
array[0] = [[' ', ' ', ' ', ' ', ' ', ' ']];
array[1] = [[' ', ' ', ' ', ' ', ' ', ' ']];
array[2] = [[' ', ' ', ' ', ' ', ' ', ' ']];
array[3] = [[' ', ' ', ' ', ' ', ' ', ' ']];
array[4] = [[' ', ' ', ' ', ' ', ' ', ' ']];
array[5] = [[' ', ' ', ' ', ' ', ' ', ' ']];
array[6] = [[' ', ' ', ' ', ' ', ' ', ' ']];
array[7] = [[' ', ' ', ' ', ' ', ' ', ' ']];
array[8] = [[' ', ' ', ' ', ' ', ' ', ' ']];
array[9] = [[' ', ' ', ' ', ' ', ' ', ' ']];
Which kind of brings me back down to earth a bit because you say you don't want any of that. It would be simpler if you used a different name than 'array' for your array, and had some actual values, as well as an actual purpose. Do you have any of that?
Bookmarks