Language: Maps
Maps are a collection of zero or more key/value pairs. These are useful for storing values that are looked up by a unique key.
Maps can be created using {}
and specifying key/value pairs. Keys and
values can be differing types. An optional trailing comma is allowed.
Examples:
Maps are unordered. When looping over a map, the key/value pairs can be returned in any order.
The set operators can be used to test for key inclusion in a map.
Accessing Elements
Map elements can be accessed with the syntax name[key]
. This looks up
a value by a key.
Accessing a key that doesn't exist results in undefined.
Examples:
Modifying or Adding Elements
Elements can be added or modified in a map by assigning to name[key]
.
If the key doesn't exist, the value is added. If the key already exists,
the value is overridden.
Deleting Elements
An element can be deleted from a map using the delete function.
Examples:
Keys and Values
The keys and values of a map can be retrieved as lists using the keys and values functions.
Because maps are unordered, the keys and values are returned in an unspecified order. It should not be assumed that keys and values will be returned in a consistent order.
Map Comparison
Maps may be compared for equality. Maps are equal if they are of equal length and both their corresponding keys and values are comparable and equal.
The current worst-case comparison speed for maps is O(N²), or quadratic time. This is the square of the cumulative elements or the parent and all child maps contained within the map. Consider this when making comparisons on larger, more complex maps. This may be optimized in the future.