MultiDimensional Arrays With Indexes

MultiDimensional Arrays With Indexes


Using bracket notation select an element from myArray such that myData is equal to 8.

What is already there:

// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[0][0];

I have no idea what to do.


bear in mind arrays are zero based, ie. first element is {0].
So, which array is the eight in? that’s the first index.
Which index in that array is the eight? that’s the second index.
So then in the last line, change the first zero to first index and second zero to second index.


If you are more visual/video oriented this video briefly goes over multi-dimensional arrays and accessing data in them.

Multi-Dimensional Array Video and Accessing elements

This other video goes over single-dimensional arrays and spends a little more time going over zero-based notion/arrays. Many languages are zero-based I took some classes in college in Java and C++ and Javascript appears to be the same, it takes a little time getting used to and you many loop debugging I have done was ultimately because of incramenting from 1 and forgetting about zero-based arrays. It just takes time and practice to think in these terms.

Single-Dimensional Arrays and zero-based indexing/language explanation


Thanks, I figured it out. Pretty easy to understand once someone explains it and doesn’t try to make it more complicated than it really is.


I will def watch these videos. Anything to help me understand. Thanks!


The trick is thinking in those concepts and being able to figure it out and debug is when an off-by-one error is buried deep in your code.

Or… transposing indexing loops etc… all comes with practice. At least that’s what I found most difficult. When I was taking formal classes I almost always wrote out my projects in pseudocode with pen and paper When I first was learning I went back to bear basics like grade school stuff using number lines for everything haha… Makes sense to me coding with computer is especially learning basics its like going over elementary concepts learned in grade school but thinking about it in a new way. Maybe even further back than that the strongest AI isn’t even really at a toddler level.

Learning is an endless loop.