Site icon i2tutorials

JavaScript WeakMap Object

 

A JavaScript WeakMap object is a type of collection that is similar to a Map. Each element is stored as a key-value pair with a weakly referenced key. In this case, the keys are objects and the values are arbitrary.

Syntax

new WeakMap([iterable]) 

Parameter

iterable – Arrays and other iterable objects whose elements are key-value pairs are represented by this type.

Points to remember

JavaScript WeakMap Methods

MethodsDescription
delete()The function deletes the specified element from the WeakMap object.
get()Upon specifying a key, it returns its value.
has()The value element indicates whether the WeakMap object contains the specified value.
set()This method adds or updates key-value pairs to the WeakMap object.

 

Exit mobile version