To determine whether there is a default value set for an associative array, use the <<Get Default Value message.
If there is no default value, Empty() is returned.
Besides the Set Default Value message, a default value can be set in the literal constructor using =>value without a key.
In the first line, the default value is set to 0. In the second line, the key "c" does not exist in counts. In the output, the key "c" is created with the default value of 0 and then incremented by 1.
To determine the number of keys that an associative array contains, use the N Items() function.
•
|
•
|
•
|
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.
|
Note that aa << 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:
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.
To obtain a list of all keys contained in an associative array, use the << Get Keys message.
To obtain a list of all values contained in an associative array, use the <<Get Values message.
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.
To obtain a list of all key-value pairs in an associative array, use the <<Get Contents message.
Note: 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:
A key can exist only once in an associative array, so putting a column’s values into one automatically results in the unique values. For example, the Big Class.jmp sample data table contains 40 rows. To see how many unique values are in the column height, run this script:
There are only 17 unique values for height. You can use those unique values by getting the keys:
Because keys are ordered lexicographically, putting the values into an associative array also sorts them. For example, the <<Get Keys message returns the keys (unique values of the names column) in ascending order:
Use N Items() to see how many countries appear in each data table:
Use the <<Intersect message to find the common values:
This example uses a set operation called intersection. For more examples of using set operations with associative arrays to compare values, see Associative Arrays in Set Operations.
This is a two-level associative array. The associative array g contains five associative arrays (1, 2, 3, 4, and 5). In the containing array g, both the keys (1-5) and the values (the arrays that define the map) are important. In the inner associative arrays, the values do not matter. Only the keys are important.
To find the intersection of two sets, use the aa << Intersect message.
Given a list of names, which of them are not contained in Big Class.jmp? You can find the answer by taking the difference of the two sets of names.