Short Description

Shows the different manners to create and access an Array in JavaScript.

Versions

  • Version 1 • Released on: 2013-03-11 13:58:57
    Download
    Description:

    initial version

    /*
     * Declare an array can be done in various ways:
     * 	- empty array and access it to put values
     *	- array initialized with values
     */
    // those two methods are equal
    a = new Array()
    a = []
    
    // those two methods are equal
    a = new Array("hello", "world", "!")
    a = ["hello", "world", "!"]
    
    // ---------------
    // Access an array
    // ---------------
    a[0] = "hello"	// put "hello" in the first element (index zero)
    a[1] = "world"	// put "world" in the second element 
    a[2] = "!"	// put "!" in the second element
    
    println(a[0])  // this displays the first element

Leave a Review