JavaScript WeakMap Reference Last Updated : 18 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report JavaScript WeakMap object in JavaScript is used to store the collection of objects (key-value pairs) in which keys are weakly referenced. The major difference between a WeakSet with a set is that a WeakSet is a collection of objects and not values of some particular type.Syntax:WeakMap.function();Example: Below is the example of weakMap.get() method. JavaScript function gfg() { const weakmap1 = new WeakMap(); const key1 = {}; weakmap1.set(key1, 12); console.log(weakmap1.get(key1)); } gfg(); Output:12The complete list of JavaScript WeakMap is listed below:JavaScript WeakMap Constructor: A constructor gets called when an object is created using the new keyword.ConstructorDescriptionweakMap()A constructor gets called when an object is created using the new keyword.JavaScript WeakMap Properties: A JavaScript property is a member of an object that associates a key with a value. Instance Properties: If the property is called on the instance of a WeakMap then it is called instance property.Instance PropertyDescriptionconstructorIt is used to return the constructor function of WeakMapJavaScript WeakMap Methods: JavaScript methods are actions that can be performed on objects.Instance Method: If the method is called on an instance of a WeakMap then it is called an instance method.Instance MethodsDescriptiondelete()Delete a particular element from an object WeakMap.get()Return a particular element from an object WeakMap.thathas()Return a boolean value that indicates whether an element with a particular key presents in the weakmap object or not.set()Set a new element with a particular key and value to a WeakMap object. Comment More infoAdvertise with us Next Article JavaScript WeakMap Reference K kartik Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Weakmap Similar Reads JavaScript WeakMap A WeakMap in JavaScript is a collection of key-value pairs where the keys are objects, and the values can be any arbitrary value. Unlike regular maps, WeakMap keys are weakly referenced, meaning they don't prevent garbage collection.The keys in a WeakMap can be automatically removed when no longer i 5 min read JavaScript weakMap set() Method The weakMap.set() is an inbuilt function in JavaScript which is used to set a new element with a particular key and value to a WeakMap object. Syntax: weakMap.set(key, value); Parameters: It takes parameters "key" which is the key of the element which is to set to the WeakMap object and parameter "v 2 min read JavaScript weakMap get() Method The Javascript weakMap.get() is an inbuilt function in JavaScript that is used to return a particular element from an object WeakMap. Syntax: weakMap.get(key);Parameters: It accepts a parameter "key" which is the key of the element which is going to be returned from the object weakmap. Return values 2 min read JavaScript weakMap has() Method The Javascript weakMap.has() is an inbuilt function in JavaScript that is used to return a boolean value which indicates whether an element with a particular key is present in the weakmap object or not. Syntax: weakMap.has(key);Parameters: It accepts a parameter 'key' which is the key of the element 2 min read JavaScript weakMap delete() Method The weakMap.delete() is an inbuilt function in JavaScript which is used to delete a particular element from an object WeakMap. Syntax: weakMap.delete(key); Parameters: It accepts a parameter "key" which is the key of the element which is going to be deleted from the object weakMap. Return values: It 2 min read Like