Syntax: Arrays

An array is like a series of variables. It can hold different individual pieces of information and you can retrieve the pieces of information individually. These segments of information are called the elements of the array. You access each element by its number in the array.

Note:
In keeping with standard programming practice arrays start counting from zero. Loop counters also start at zero. If you want to start counting your array elements at 1 you will need to make the array 1 larger than it should be and ensure that loops you use with the array also start at 1.

Syntax: To create (i.e. declare) an Array

var arrayName = new Array()

or

var arrayName = new Array( number

Remarks:

var – the keyword var is used to declare and initialise a new variable.

arrayName – the name you will give to the Array.

new Array() – the keyword new is used to create a new object and Array is the object type you are creating.

() – the brackets contain the number of elements in the array. If the number of elements is omitted, the number of elements can be expanded as required.

Syntax: To use (i.e. reference) elements of an Array:

arrayName[ elementNumber ]

Remarks:

arrayName – the name you gave to the Array.

elementNumber – the number of the element within the array. The first element is number 0, the second is 1 and so on.

[ ] – the elementNumber must be surrounded by square brackets.

Note:
You can use the value of an element in a statement (see examples).

Reverse Array

Once the elements of an array have been established you can reverse their order in the array with a simple command:

arrayName.reverse()

 

Sort Array

In common with Javascript Opus also provides a function to sort the contents of the array into alphabetical order with a similar simple command:

arrayName.sort()

This will reorganise the chosen array into ascending alphabetical order a-z. Note that this does not sort on numerical values - it will sort numbers according to the lexicographical value. Thus 1001 will come before 112.

image\Script_Button.jpgExamples