To determine the number of keys that an associative array contains, use the N Items() function.
N Items( cary );
•
|
•
|
•
|
Insert() and Remove() return a named copy of the given associative array with the key-value pair added or removed.
|
•
|
Insert Into() and Remove From() add or remove the key-value pairs directly from the given associative array.
|
•
|
Insert() and Insert Into() take three arguments: the associative array, a key, and a value.
|
•
|
Remove() and Remove From() take two arguments: the associative array and a key.
|
Show( cary, newcary );
Show( cary );
Note that cary <<Insert is a message sent to an associative array that does the same thing as the function Insert Into(). For example, these two statements are equivalent:
Show( cary, newcary );
Remove From( cary, "weather" );
Show( cary );
Note that aa << Remove is a message sent to an associative array that does the same thing as the function Remove From(). For example, these two statements are equivalent:
To determine whether a certain key is contained within an associative array, use the Contains() function.
Contains(cary, "high schools");
Contains(cary, "lakes");
To obtain a list of all keys contained in an associative array, use the << Get Keys message.
cary << Get Keys;
To obtain a list of all values contained in an associative array, use the <<Get Values message.
cary << Get Values;
cary << Get Values({"state", "population"});
To see a value for a single key, use the <<Get Value message. Specify only one key and do not place it in a list.
cary << Get Value("weather");
To obtain a list of all key-value pairs in an associative array, use the <<Get Contents message.
cary << Get Contents;
注意:Using the <<Get Contents message, the returned list does not include the default value. Keys are listed alphabetically.
To iterate through as associative array, use the <<First and <<Next messages. <<First returns the first key in the associative array. <<Next(key) returns the key that follows the key that is given as the argument.
The following example removes all key-value pairs from the associative array cary, leaving an empty associative array:
currentkey = cary << First;
total = N Items( cary );
For( i = 1, i <= total, i++,
nextkey = cary << Next( currentkey );
Show( cary );