Map<K, V>
A key-value store mapping keys of type K to values of type V.
Keys must be hashable: int, float, bool, string, color, or enum. Create with Map.new() or a map literal {"key": value}.
Kind: object
Static Methods
new
Map.new(): const Map<K, V>Creates a new empty map of the specified key and value types.
Returns: const Map<K, V>
Methods
clear
Map.clear(id: Map<K, V>)Clears all entries from the given map.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Map<K, V> | the map to clear. |
contains
Map.contains(id: Map<K, V>, key: K): boolChecks if the specified key exists in the given map.
It returns true if the key is found, otherwise false.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Map<K, V> | the map to search in. | |
key | K | The key to check for existence. |
Returns: bool
copy
Map.copy(id: Map<K, V>): Map<K, V>Creates a copy of the given map and returns the new id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Map<K, V> | the map to copy. |
Returns: Map<K, V>
get
Map.get(id: Map<K, V>, key: K): VRetrieves the value associated with the specified key in the given id, or returns na if the key does not exist.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Map<K, V> | the map to retrieve the value from. | |
key | K | The key to look up in the map. |
Returns: V — The value associated with key, or na if the key does not exist.
keys
Map.keys(id: Map<K, V>): Array<K>Returns an array containing all the keys present in the given id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Map<K, V> | the map to get the keys from. |
Returns: Array<K>
put
Map.put(id: Map<K, V>, key: K, value: V): VInserts or updates the value associated with the specified key in the given map.
It returns the previous value if the key existed, or na if it is a new entry.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Map<K, V> | the map to insert or update a value in. | |
key | K | The key to associate with the value. | |
value | V | The value to insert or update. |
Returns: V — The previous value associated with key, or na if the key was not previously present.
put_all
Map.put_all(id: Map<K, V>, id2: Map<K, V>)Copies all key-value pairs from the source map to the destination id.
Existing keys in the destination id will be updated with values from the source id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Map<K, V> | The destination id to copy values into. | |
id2 | Map<K, V> | The source id to copy values from. |
remove
Map.remove(id: Map<K, V>, key: K): VRemoves the entry associated with the specified key from the given map.
It returns the removed value if the key existed, or na if the key was not found.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Map<K, V> | the map to remove a value from. | |
key | K | The key of the entry to remove. |
Returns: V — The removed value, or na if the key was not found.
size
Map.size(id: Map<K, V>): intReturns the number of key-value pairs currently stored in the given map.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Map<K, V> | the map to get the size of. |
Returns: int
values
Map.values(id: Map<K, V>): Array<V>Returns an array containing all the values present in the given id.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | Map<K, V> | the map to get the values from. |
Returns: Array<V>