In this example we have created an array variable that stores six values. Each value contains the name of a fruit.
var fruits = ["Apple", "Orange", "Pear", "Grape", "Tangerine", "Mango"];
document.getElementById("demo").innerHTML = fruits;
In order to output a specific value in the array, we can refer to it using an index number. The index number starts with 0. The first item in the array is identified by the index number 0, in this case Apple. If the index number was 1, we would be referencing Orange and so on.
Let's preview this page in our browser to see the result. We can see here that the first value is outputted (Apple).
We can use the
length property to determine the number of values stored in an array.
document.getElementById("demo").innerHTML = fruits.length;