Array constructor

Provides a reference for array constructors in IBM ILOG Script.

The array constructor has two distinct forms.

Table 1. Array constructor
Syntax Effect
new Array(length)

Returns a new array a of length length with its elements from 0 to length-1 set to null.

If length is not a number, and its conversion to a number yields NaN, the second syntax is used.

Examples:

new Array(12) –> an array a with length 12 and a[0] to a[11] containing null

new Array("5") –> an array a with length 5 and a[0] to a[4] containing null

new Array("foo") see second syntax

new Array(element1, ..., elementn)

Returns a new array a of length n with a[0] containing element1, a[1] containing element2, and so on. If no argument is given, that is n=0, an empty array is created. If n=1 and element1 is a number or can be converted to a number, the first syntax is used.

Examples:

new Array(327, "hello world") –> an array a of length 2 with a[0] == 327 and a[1] == "hello world"

new Array() –> an array with length 0

new Array("327") see first syntax