Dictionary
Documentation for the Dictionary type.
A map from string keys to values.
You can construct a dictionary by enclosing comma-separated key: value pairs in parentheses. The values do not have to be of the same type. Since empty parentheses already yield an empty array, you have to use the special (:) syntax to create an empty dictionary.
A dictionary is conceptually similar to an array, but it is indexed by strings instead of integers. You can access and create dictionary entries with the .at() method. If you know the key statically, you can alternatively use field access notation (.key) to access the value. To check whether a key is present in the dictionary, use the in keyword.
You can iterate over the pairs in a dictionary using a for loop. This will iterate in the order the pairs were inserted / declared initially.
Dictionaries can be added with the + operator and joined together. They can also be spread into a function call or another dictionary1 with the ..spread operator. In each case, if a key appears multiple times, the last value will override the others.
Example
Constructor
Converts a value into a dictionary.
Note that this function is only intended for conversion of a dictionary-like value to a dictionary, not for creation of a dictionary from individual pairs. Use the dictionary syntax (key: value) instead.
#dictionary(
value
) -> dictionaryParameters
Prop
Type
Methods
The number of pairs in the dictionary.
Returns the value associated with the specified key in the dictionary. May be used on the left-hand side of an assignment if the key is already present in the dictionary. Returns the default value if the key is not part of the dictionary or fails with an error if no default value was specified.
#dictionary.at(
key,
default: any
) -> anyParameters
Prop
Type
Inserts a new pair into the dictionary. If the dictionary already contains this key, the value is updated.
To insert multiple pairs at once, you can just alternatively another dictionary with the += operator.
#dictionary.insert(
key,
value
) -> Parameters
Prop
Type
Removes a pair from the dictionary by key and return the value.
#dictionary.remove(
key,
default: any
) -> anyParameters
Prop
Type
Returns the keys of the dictionary as an array in insertion order.
Returns the values of the dictionary as an array in insertion order.
Returns the keys and values of the dictionary as an array of pairs. Each pair is represented as an array of length two.
Produces a new dictionary with only the pairs from the original one for which the given function returns true.
#dictionary.filter(
test
) -> dictionaryParameters
Prop
Type
Produces a new dictionary where the keys are the same, but the values are transformed with the given function.
#dictionary.map(
mapper
) -> dictionaryParameters
Prop
Type