- The array is a special type of variable.
- Values are stored into an array by using the array name and by stating the location in the array you wish to store the value in brackets. Example: myArray = "Hello World";
- Values in an array are accessed by the array name and location of the value. Example: myArray;
var myArray = new Array();
myArray = "Football";
myArray = "Baseball";
myArray = "Cricket";
document.write(myArray + myArray + myArray);
Notice that you set values and get values from an array by specifying the position, in brackets, of the value you want to use.
Imagine that you wanted to sort an array alphabetically before you wrote the array to the browser. Well, this code has already been written and can be accessed by using the Array's sort method.
var myArray2= new Array();
myArray2 = "Football";
myArray2 = "Baseball";
myArray2 = "Cricket";
document.write(myArray2 + myArray2 + myArray2);
Found Something Wrong in this Lesson?
Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time!