0
What is the index naming logic in multidimensional arrays
3 ответов
+ 1
[0][0]
[0][1]
[0][2]
[1][0]
[1][1]
[1][2]
i think this explains
+ 1
Uses a matrix notation, the ith, jth...nth terms specify a particular element within a multidimesional array, it's easy to visualize this using nested loops to iterate over elements in a multidimesional arrays.
0
Not sure if existing answers explain it for everybody. For two-dimensiomal arrays which is what you mostly need: Think of excel with columns and rows.
In actual fact you have arrays in one array here: One outer array and multiple inner arrays. Which means every element in the outer array contains another array.
Its as if you wrote: ( [ ] creates a new empty array )
var outerArray = [ ];
outerArray[0] = [ ];
outerArray[1] = [ ];
outerArray[2] = [ ];
outerArray[3] ...
So you first specify which index you want to access from the outerArray and then the index from the innerArray. So this looks like this:
var indexOuter = 3; // Just so you see what I
// use the index for.
var indexInner = 1; // ... same reason.
// Now we access the fourth element
// of the outer array and then the second
// element of the inner array
var element = outerArray[indexOuter][indexInner];
Hope this clrears things up more.