What is the index naming logic in multidimensional arrays | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the index naming logic in multidimensional arrays

20th Jul 2016, 1:12 PM
Umed Jadhav
Umed Jadhav - avatar
3 Answers
+ 1
[0][0] [0][1] [0][2] [1][0] [1][1] [1][2] i think this explains
20th Jul 2016, 3:27 PM
sreeraj g
sreeraj g - avatar
+ 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.
21st Jul 2016, 4:38 AM
Eric Gitangu
Eric Gitangu - avatar
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.
24th Jul 2016, 2:30 PM
MarquisBs
MarquisBs - avatar