Returns the key name of the element following the specified key in an associative array.

Syntax

<oRef>.nextKey(<key expC>)

<oRef>

A reference to the associative array that contains the key.

<key expC>

An existing key name.

Property of

AssocArray

Description

Use nextKey( ) to loop through the elements in an associative array. Once you have determined the key name for the first element with firstKey, use nextKey( ) to get the key names for the rest of the elements.

nextKey( ) returns the key name for the key following <key expC>. Key names in associative arrays are case-sensitive. For the last key in the associative array and for a <key expC> that is not an existing key name, nextKey( ) returns the logical value false. Because false is a different data type than valid key names (which are character strings), it’s difficult to look for false to terminate a loop. It’s easier to get the number of elements in the array first with count( ); then loop through that many iterations.

Note

The order of elements in an associative array is undefined. They are not necessarily stored in the order in which you add them, or sorted by their key names. You can’t assume that the sequence of keys will be consistent.

To determine if a given character string is a key name in an associative array, use isKey( ).