The Array object is used to store multiple values in a single variable.
An array is a special variable, which can hold more than one value, at a time.
If you have a list of items (a list of car names, for example), storing the cars in single variables could look like this:
However, what if you want to loop through the cars and find a specific one? And what if you had not 3 cars, but 300?
The best solution here is to use an array!
An array can hold all your variable values under a single name. And you can access the values by referring to the array name.
Each element in the array has its own ID so that it can be easily accessed.
You refer to containers in the array as arrayName, arrayName, arrayName, and so on. Each of these individual containers can be manipulated and used just like a regular variable.
Create an Array
An array can be defined in three ways. The following code creates an Array object called myCars:
myCars=”Saab”; // argument to control array’s size)
Access an Array
You can refer to a particular element in an array by referring to the name of the array and the index number. The index number starts at 0.The following code line:
Modify Values in an Array
Here the value at index 0 has been assigned a new value in myCars array.