A one-dimensional associative array, in which the elements can be referenced by string.

Syntax

[<oRef> =] new AssocArray( )

<oRef>

A variable or property in which to store a reference to the newly created AssocArray object.

Properties

The following tables list the properties and methods of the AssocArray class. (No events are associated with this class.)

Property

Default

Description

baseClassName

ASSOCARRAY

Identifies the object as an instance of the AssocArray class

className

(ASSOCARRAY)

Identifies the object as an instance of a custom class. When no custom class exists, defaults to baseClassName

firstKey

 

Character string assigned as the subscript of the first element of an associative array

 

Method

Parameters

Description

count( )

 

Returns the number of elements in the associative array

isKey( )

<key expC>

Returns true or false to indicate whether the character string is a key of the associative array

nextKey( )

<key expC>

Returns the associative array key following the passed key

removeAll( )

 

Deletes all elements from the associative array

removeKey( )

<key expC>

Deletes the specified element from the associative array

Description

In an associative array, elements are associated with arbitrary character strings, which act as key values. The keys may be of any length, and are case-sensitive. An AssocArray is a one-dimensional array.

New elements are created simply by assigning a value to a key. If the key does not exist, a new element is created. If the key already exists, then the old value is replaced. For example,

aTest = new AssocArray( )

aTest[ "alpha" ] = 1 // Create element with key "alpha" value 1

aTest[ "beta" ] = 2 // Create element with key "beta" value 2

aTest[ "alpha" ] = 3 // Change value of element "alpha" to 3

aTest[ "Beta" ] = 4 // Create element with key "Beta" value 4

The isKey( ) method will check if a given string is a key value in the associative array, and removeKey( ) will remove the element for a given key value from the array. removeAll( ) removes all the elements from the array.

The order of elements in an associative array is undefined. They are not necessarily sorted in the order they were added or sorted by their key values. You can think of an associative array as a bag of elements, and depending on what’s in the bag, the order is different. But no matter what’s in the associative array, you can use its firstKey property to get a key value, and use the nextKey( ) method to get all the other key values. The count( ) method will return the number of elements in the array so that you can call nextKey( ) as many times as needed.