Javascript: Array

This entry is part 17 of 27 in the series Javascript Tutorial

An array is a variable that can store many variables within it.

Variables are stored sequentially and the arrays are zero-indexed: the first element of an array is at index 0, and the last element is at the index equal to the value of the array’s length property minus 1.

<!DOCTYPE html>
        function aFunction() {
            var fruits = new Array("apple", "orange", "mango");
            document.getElementById("fruit_id").innerHTML = fruits[1];
<p>I like</p>
<p id="fruit_id">fruit</p>
<button onclick="aFunction()">Click Me</button>
In this fruit array, fruit[0] is apple and fruit[1] is orange.
Series Navigation<< Javascript: While loop
Javascript: A simple form >>

Leave a comment

Leave a Reply