Class WeakMap
The WeakMap is map whose entries are subject to garbage collection if there are no more references to the keys. Keys must be objects (no primitives). Elements can't be iterated.
API Version:
Available from version 21.2.
| Property | Description |
|---|---|
| size: Number | Number of key/value pairs stored in this map. |
| Constructor | Description |
|---|---|
| WeakMap() | Creates an empty map. |
| WeakMap(Iterable) | If the passed value is null or undefined then an empty map is constructed. |
| Method | Description |
|---|---|
| clear() | Removes all key/value pairs from this map. |
| delete(Object) | Removes the entry for the given key. |
| get(Object) | Returns the value associated with the given key. |
| has(Object) | Returns if this map has value associated with the given key. |
| set(Object, Object) | Adds or updates a key/value pair to the map. |
assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values
- size: Number
Number of key/value pairs stored in this map.
- WeakMap()
Creates an empty map.
- WeakMap(values: Iterable)
If the passed value is null or undefined then an empty map is constructed. Else an iterator object is expected that produces a two-element array-like object whose first element is a value that will be used as a Map key and whose second element is the value to associate with that key.
Parameters:
- values - The initial map values
- clear(): void
Removes all key/value pairs from this map.
- delete(key: Object): Boolean
Removes the entry for the given key.
Parameters:
- key - The key of the key/value pair to be removed from the map.
Returns:
trueif the map contained an entry for the passed key that was removed. Elsefalseis returned.
- get(key: Object): Object
Returns the value associated with the given key.
Parameters:
- key - The key to look for.
Returns:
- The value associated with the given key if an entry with the key exists else
undefinedis returned.
- has(key: Object): Boolean
Returns if this map has value associated with the given key.
Parameters:
- key - The key to look for.
Returns:
trueif an entry with the key exists elsefalseis returned.
- set(key: Object, value: Object): WeakMap
Adds or updates a key/value pair to the map.
Parameters:
- key - The key object.
- value - The value to be associate with the key.
Returns:
- This map object.