The JavaScript WeakMap object is a type of collection which is almost similar to Map. It stores each element as a key-value pair where keys are weakly referenced. Here, the keys are objects and the values are arbitrary values.
Syntax
new WeakMap([iterable])
Parameter
iterable – It represents an array and other iterable object whose elements are in the form of key-value pair.
Points to remember
- A WeakMap object allows the keys of object type only.
- In WeakMap, if there is no reference to a key object, they are targeted to garbage collection.
- In WeakMap, the keys are not enumerable. So, it doesn’t provide any method to get the list of keys.
- A WeakMap object iterates its elements in insertion order.
Leave a Reply