contents   index   previous   next



Array object

 

An Array object is an object in JavaScript and is in the underlying ECMAScript standard. Be careful not to confuse an array variable that has been constructed as an instance of the Array object with the automatic or dynamic arrays of ScriptEase. ScriptEase offers automatic arrays in addition to the Array object of ECMAScript. The purpose is to ease the programming task by providing another easy to use tool for scripters. The current section is about Array objects.

 

An Array is a special class of object that refers to its properties with numbers rather than with variable names. Properties of an Array object are called elements of the array. The number used to identify an element, called an index, is written in brackets following an array name. Array indices must be either numbers or strings.

 

Array elements can be of any data type. The elements in an array do not all need to be of the same type, and there is no limit to the number of elements an array may have.

 

The following statements demonstrate assigning values to arrays.

 

var array = new Array();

array[0] = "fish";

array[1] = "fowl";

array["joe"] = new Rectangle(3,4);

array[foo] = "creeping things"

array[goo + 1] = "etc."

 

The variables foo and goo must be either numbers or strings.

 

Since arrays use a number to identify the data they contain, they provide an easy way to work with sequential data. For example, suppose you wanted to keep track of how many jellybeans you ate each day, so you can graph your jellybean consumption at the end of the month. Arrays provide an ideal solution for storing such data.

 

var April = new Array();

April[1] = 233;

April[2] = 344;

April[3] = 155;

April[4] = 32;

 

Now you have all your data stored conveniently in one variable. You can find out how many jellybeans you ate on day x by checking the value of April[x]:

 

for(var x = 1; x < 32; x++)

   Screen.write("On April " + x + " I ate " + April[x] +

      " jellybeans.\n");

 

Arrays usually start at index [0], not index [1]. Note that arrays do not have to be continuous, that is, you can have an array with elements at indices 0 and 2 but none at 1.

 

 

see:

array.jsh - arrays and objects

 


Creating arrays

Array object instance properties

Array object instance methods