Link Search Menu Expand Document

6.1 Array Object Overview

The CRS language supports one-dimensional arrays, and most objects can be defined as arrays.

Example :

Number num[3];

Objects defined as an array can access the array elements by subscripts. For the subscript, specify an integer starting from 0. Associative arrays with strings as subscripts used in JavaScript Array objects etc. are not supported. (The Array class supports associative arrays)

Example :

Number num[3];
for( var n = 0; n < 3; n++ ) {
    num[n] = n * 10;
}
print( num[0], num[1], num[2], "\n" );

Actual result
0  10  20

All array objects function as variable-length arrays, and the number of elements can be dynamically changed using the Insert and Truncate methods for array operations.

Deleting an array element with the Delete method also deletes the element from the array object.

Reference: Array class

Aside from the array object, similar processing can be done by using the Array class. The Array class is not an array as a CRS language, but it can access elements by subscripts.

Unlike array objects, the Array class has the following characteristics.

  1. The number of elements is automatically expanded by accessing the elements.
  2. 
    
    
    
    var a = new Array;
    a[0] = 1;
    a[5] = 3;
    

    In this example, the element of a is expanded from 0 to 5.
  3. Individual elements can contain objects of different types.
  4. Button button1;
    TextBox text1;
    var a = new Array;
    a [0] = button1;
    a [1] = text1;
    

    In this example, the first element contains the Button object and the second element contains the TextBox object's reference.
  5. Supports associative arrays with strings as subscripts.
  6. var a = new Array;
    a["ABC"] = 1;
    a["DEF"] = 2;
    

  7. In addition, the elements can be sorted by the method peculiar to the Array class.
  8. Refer the Array class section for more information.