Lodash _.isWeakMap() Method

The _.isWeakMap() method is used to find whether the given value is a weakmap object or not. It returns True if the given value is a weakmap object. Otherwise, it returns false.

Syntax:

_.isWeakMap(value)

Parameters: This method accepts a single parameter as mentioned above and described below:

  • value: This parameter holds the value to check.

Return Value: This method returns true if value is a weakmap, else false.



Note: Here, const _ = require(‘lodash’) is used to import the lodash library into the file.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Requiring the lodash library  
const _ = require("lodash");  
       
// Creating a array of size 2
// using constructor 
var obj= new Array(2); 
  
// Filling value 5 in the array 
obj.fill(5) 
      
// Use of _.isWeakMap() method 
console.log(_.isWeakMap(obj)); 

chevron_right


Output:

false

Example 2:  

filter_none

edit
close

play_arrow

link
brightness_4
code

// Requiring the lodash library  
const _ = require("lodash");  
       
// Use of _.isWeakMap() method 
  
// When a weak set is given
console.log(_.isWeakMap(new WeakMap)); 
  
// When a weak set is not given
console.log(_.isWeakMap(new Map));

chevron_right


Output:

true
false

Note: This will not work in normal JavaScript because it requires the library lodash to be installed.

Reference: https://lodash.com/docs/4.17.15#isWeakMap

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.