Visualizing Two Dimensional Arrays
Whereas, one dimensional arrays can be visualized as a stack of elements, two dimensional arrays can be visualized as a multicolumn table or grid.
For example, we could create a two dimensional array that holds three columns of data; a question, an answer, and a topic.
|Two Dimensional Array|
|0||Arrays||What is an array?||An ordered stack of data|
|1||Arrays||How to create arrays?||Assign variable name to array object, then assign values to the array.|
|2||Arrays||What are two dimensional arrays?||An ordered grid of data|
Creating Two Dimensional Arrays
To do this, you create an array, loop through the array, and for each element, you create another array. Then, you simply add an index for each column of your grid. In JavaSript this would look something like this:
var faq = new Array(3) for (i=0; i <3; i++) faq[i]=new Array(3) faq = "Arrays" faq = "What is an array?" faq = "An ordered stack of data" faq = "Arrays" faq = "How to create arrays?" faq = "Assign variable name to array object, then assign values to the array." faq = "Arrays" faq = "What are two dimensional arrays?" faq = "An ordered grid of data"