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)


/* Arrays in Jsi */
// Create a new array with length 0
var myArray = new Array();
;myArray;
 
// In Jsi, typeof [] is "array".  In ECMAScript, typeof [] is "object"
;typeof [];
 
// Create a new array with length 5
var myArray1 = new Array(5);
;myArray1;
 
// Create an array with 2 members (length is 2) 
var myArray2 = new Array("Item1","Item2");
;myArray2;
;myArray2.length;
 
// Create an array with 2 members using an array literal
var myArray3 = ["Item1", "Item2"];
;myArray3;
 
// Assign a value to member [2] (length is now 3)
myArray3[2] = 5;
;myArray3;
;myArray3.length;
 
var x = myArray3[2] + myArray3.length;   // 8
;x;
 
// You can also add a member to an array with the push function (length is now 4)
myArray3.push('Test');
;myArray3;
;myArray3.length;
 
// Empty array entries in a literal is a syntax error, elisions not allowed
//var badSyntax = [1,2,,4];
 
 
/*
=!EXPECTSTART!=
myArray ==> []
typeof [] ==> array
myArray1 ==> [ undefined, undefined, undefined, undefined, undefined ]
myArray2 ==> [ "Item1", "Item2" ]
myArray2.length ==> 2
myArray3 ==> [ "Item1", "Item2" ]
myArray3 ==> [ "Item1", "Item2", 5 ]
myArray3.length ==> 3
x ==> 8
myArray3 ==> [ "Item1", "Item2", 5, "Test" ]
myArray3.length ==> 4
=!EXPECTEND!=
*/