JavaScript weakMap get() Method Last Updated : 07 Aug, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: It returns the element which is associated with the particular key in the WeakMap object and it returns undefined if the key can not be found. Below is an example of weakMap.get() method. Example 1: This example shows the basic use of the weakmap().get method. javascript function gfg() { const weakmap1 = new WeakMap(); const key1 = {}; weakmap1.set(key1, 12); console.log(weakmap1.get(key1)); } gfg(); Output12Example 2: Here we get the output as 42 because we have set the value to 42. javascript // Creating a WeakMap() object const weakmap1 = new WeakMap(); // Creating a key "key1" const key1 = {}; // setting value 42 with key "key1" in the // object weakMap weakmap1.set(key1, 42); // Getting the specified elements i.e, 42 console.log(weakmap1.get(key1)); Output42Example 3: In this example, we will see the basic use of weakmap.get() method,.Here the output is undefined because the key "key1" has not been set at the end of the weakMap object. javascript // Creating a WeakMap() object const weakmap1 = new WeakMap(); // Creating a key "key1" const key1 = {}; // Getting the specified elements console.log(weakmap1.get(key1)); OutputundefinedWe have a complete list of Javascript WeakMap methods, to check those please go through Javascript WeakMap Complete reference article. Supported Browsers:Google Chrome 36 and aboveEdge 12 and aboveFirefox 6 and aboveInternet Explorer 11 and aboveOpera 23 and aboveSafari 8 and above Comment More infoAdvertise with us Next Article JavaScript weakMap has() Method S ShivamKD Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Weakmap JavaScript-Methods Similar Reads JavaScript WeakMap() Constructor The WeakMap() Constructor produces WeakMap objects that are a key/value pair array in which the key is referenced weakly. The keys should be objects and the values could be arbitrary. The difference between Map and WeakMap is that keys must be objects and are only weakly referenced. This means that 2 min read JavaScript WeakMap constructor Property JavaScript WeakMap constructor property is used to return the WeakMap constructor function for the object. The function returned by this property is just the reference, not the actual WeakMap. It is an object property of JavaScript and can be used with Strings, Numbers, etc. Syntax: weakset.construc 1 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 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 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 Like