We can create two dimensional arrays in JavaScript. These arrays are different than two dimensional arrays we have used in ASP. To understand two dimensional arrays we will use some examples. First let us try to create some arrays.
var details = new Array();
details[0]=new Array(3);
details[0][0]="Example 1";
details[0][1]="Example 2";
details[0][2]="Example 3";
As you have seen we have declared a array and named it as details. Then we have added elements to this array. Now to access the elements we have to address them like this.
document.write(details[0][2]);
This will give the output as Example 3
Displaying elements of two dimensional array
To display the inner elements of first set of array we have to use for loop. Here is an example.
Example 1
Example 2
Example 3
Example 4
Example 5
undefined
Note the last line saying undefined. This is because we have not added any element to details[1][2]
Displaying elements by using length Property
In above code we used numbers inside for loops because we already know the number of elements present inside array. If we don't know the number of elements present inside array then we can use the array length property inside for loop to display the elements.