Java Reference
In-Depth Information
So what's going on? Well, the truth is that JavaScript doesn't actually support multi‐dimensional arrays,
only single ones. However, JavaScript enables you to fake multi‐dimensional arrays by creating an array
inside another array. So what the preceding line is doing is creating a new array inside the element with
index 0 of your personnel array.
In the next three lines, you put values into the newly created personnel[0] array. JavaScript makes
it easy to do this: You just state the name of the array, personnel[0] , followed by another index in
square brackets. The first index ( 0 ) belongs to the personnel array; the second index belongs to the
personnel[0] array:
personnel[0][0] = "Name0";
personnel[0][1] = "Age0";
personnel[0][2] = "Address0";
After these lines of code, your array looks like this:
index
0
0
Name0
1
Age0
2
Address0
The numbers at the top, at the moment just 0 , refer to the personnel array. The numbers
going down the side, 0 , 1 , and 2 , are actually indices for the new personnel[0] array inside the
personnel array.
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] = [];
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:
Search WWH ::




Custom Search