A mapping of generic keys to generic values.
.get with a key that does not exist results in an error, because
undefined cannot be represented. Example:
var map = new Map<i32,string>() // Because `undefined` cannot be represented if a key is not found, this will error: var str = map.get(1) // ERROR // The error can be avoided by first making sure that the key exists, so this works: var str: string | null = map.has(1) ? map.get(1) : null // OK
- Constructs a new map mapping keys of type
Kto values of type
# Instance members
- The current number of key-value pairs in this map.
readonly size: i32
function clear(): void
Clears the map, deleting all key-value pairs.
function delete(key: K): bool
Deletes the key-value pair for the corresponding key. Returns
trueif the key did exist, otherwise
function get(key: K): V
Gets the value corresponding to the specified key. Traps if the key does not exist because "not found" cannot be represented in all cases (use
function has(key: K): bool
Tests if the specified key exists.
function keys(): Array<K>
Gets the keys contained in this map as an array, in insertion order. This is preliminary while iterators are not supported.
function set(key: K, value: V): this
Sets the value for the specified key. Creates a new key-value pair if the key did not exist.
function values(): Array<V>
Gets the values contained in this map as an array, in insertion order. This is preliminary while iterators are not supported.
function toString(): string
Returns a string representation of this map.