This task is about arrays.

For hashes or associative arrays, please see Creating an Associative Array.

For a definition and in-depth discussion of what an array is, see Array.



Task

Show basic array syntax in your language.

Basically, create an array, assign a value to it, and retrieve an element   (if available, show both fixed-length arrays and
dynamic arrays, pushing a value into it).

Please discuss at Village Pump:   Arrays.

Please merge code in from these obsolete tasks:

   Creating an Array
   Assigning Values to an Array
   Retrieving an Element of an Array


Related tasks

   Collections
   Creating an Associative Array
   Two-dimensional array (runtime)


// Create a new array with length 0
var myArray = new Array();
 
// Create a new array with length 5
var myArray1 = new Array(5);
 
// Create an array with 2 members (length is 2) 
var myArray2 = new Array("Item1","Item2");
 
// Create an array with 2 members using an array literal
var myArray3 = ["Item1", "Item2"];
 
// Assign a value to member [2] (length is now 3)
myArray3[2] = 5;
 
var x = myArray[2] + myArray.length;   // 8
 
// You can also add a member to an array with the push function (length is now 4)
myArray3.push('Test');
 
// Elisions are supported, but are buggy in some implementations
var y = [0,1,,];  // length 3, or 4 in buggy implementations 
 