Java Reference
In-Depth Information
For the second person's details, you repeat the process, but this time you are using the personnel array
element with index 1.
personnel[1] = new Array();
personnel[1][0] = “Name1”;
personnel[1][1] = “Age1”;
personnel[1][2] = “Address1”;
Now your array looks like this:
Index
0
1
0
Name0
Name1
1
Age0
Age1
2
Address0
Address1
You create a third person's details in the next few lines. You are now using the element with index 2
inside the personnel array to create a new array.
personnel[2] = new Array();
personnel[2][0] = “Name2”;
personnel[2][1] = “Age2”;
personnel[2][2] = “Address2”;
The array now looks like this:
Index
0
1
2
0
Name0
Name1
Name2
1
Age0
Age1
Age2
2
Address0
Address1
Address2
You have now fi nished creating your multi-dimensional array. You end the script block by accessing
the data for the second person ( Name1 , Age1 , Address1 ) and displaying it in the page by using document
.write() . As you can see, accessing the data is very much the same as storing them. You can use the
multi-dimensional array anywhere you would use a normal variable or single-dimension array.
document.write(“Name : “ + personnel[1][0] + “<BR>”);
document.write(“Age : “ + personnel[1][1] + “<BR>”);
document.write(“Address : “ + personnel[1][2]);
Try changing the document.write() commands so that they display the fi rst person's details. The
code would look like this:
document.write(“Name : “ + personnel[0][0] + “<BR>”);
document.write(“Age : “ + personnel[0][1] + “<BR>”);
document.write(“Address : “ + personnel[0][2]);
Search WWH ::




Custom Search