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)


 
var arr1 = [1,2,3,4]   // initialize with array literal
var arr2 = new [10]   // empty array of 10 elements (each element has value none)
var arr3 = new int [40]  // array of 40 integers
var arr4 = new Object (1,2) [10]   // array of 10 instances of Object
 
arr1.append (5)   // add to array
var b = 4 in arr1   // check for inclusion
arr1 <<= 2           // remove first 2 elements from array
var arrx = arr1[1:3]   // get slice of array
var s = arr1.size()  // or sizeof(arr1)
delete arr4[2]     // remove an element from an array
 
var arr5 = arr1 + arr2   // append arrays
var arr6 = arr1 | arr2    // union
var arr7 = arr1 & arr2   // intersection
 
 