devxlogo

Multi-dimensional Arrays

Multi-dimensional Arrays

Question:
Can I create multi-dimensional arrays in JavaScript? Do you have an example?

Answer:
Yes and no.

You can’t create multi-dimensional arrays (as such) in JavaScript. What you can do is create an array of arrays, though.For instance, you can have:

numberArray = new Array("one","two","three")letterArray = new Array("a","b","c")bigArray = new Array(numberArray,letterArray)

You could later reference bigArray[0][1], which would be “b” (arrays are zero-relative).

devx-admin

Share the Post: