Creating an array is simple...
var numbers = new Array(3);
This will create a array called 'numbers' that can hold three elements. Now to fill it with numbers.
numbers = 13;
numbers = 0;
numbers = 100;
The first line is numbers. Notice the 0? One thing to remember about arrays is that arrays start with 0 - not with 1. So the first element of an array is its 0'th item, second is 1'st item and so on.
Another way of creating the same array is given below...
var numbers = new Array(13,0,100);
This will create the array and insert 3 elements - 13, 0 and 100. You can access any element of the array if you know its index. The below code will display the third item of the array - 100.
The same method can be used to edit the elements...
number = 1;
Although the above methods will create an array, this will be the most easiest way to create one...
var numbers = [13,0,100];
Now to see a full example on arrays.
Click on the Run button to see the result.blog comments powered by Disqus