JavaScript WeakMap Object

 

Syntax


Code

  1. 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.

JavaScript WeakMap Methods

MethodsDescription
delete()It deletes the specified element from the WeakMap object.
get()It returns the value of specified key.
has()It indicates whether the WeakMap object contains the specified value element.
set()It adds or updates the key-value pairs to WeakMap object.



0 Comments