Java Reference
In-Depth Information
You can treat each particular position in an array as if it's a standard variable. So you can use it to do
calculations, transfer its value to another variable or array, and so on. However, if you try to access the
data inside an array position before you have defi ned it, you'll get undefined as a value.
Finally, you change the value of the second array position to “Mike” . You could have changed it to a
number because, just as with normal variables, you can store any data type at any time in each indi-
vidual data position in an array.
myArray[1] = “Mike”;
Now your array's contents look like this:
Index
Data Stored
0
Bob
1
Mike
2
Paul
Just to show that the change you made has worked, you use document.write() to display the second
element's value.
document.write(“myArray[1] changed to “ + myArray[1]);
A Multi-Dimensional Array
Suppose you want to store a company's personnel information in an array. You might have data such
as names, ages, addresses, and so on. One way to create such an array would be to store the information
sequentially — the fi rst name in the fi rst element of the array, then the corresponding age in the next
element, the address in the third, the next name in the fourth element, and so on. Your array could look
something like this:
Index
Data Stored
0
Name1
1
Age1
2
Address1
3
Name2
4
Age2
5
Address2
6
Name3
7
Age3
8
Address3
Search WWH ::




Custom Search