Underscore.js _.isWeakMap() Function
Last Updated :
25 Nov, 2021
Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.isWeakMap() function is used to check whether the given object is javascript weakmap or not. When linking the underscore.js CDN The “_” is attached to the browser as global variable.
Syntax:
_.isWeakMap(object);
Parameters :
- object: It is any javascript object such as array, string, maps, set etc.
Returns: It returns the boolean value. If the object is a weak map of javascript it returns true otherwise false is returned by the function.
Few Examples are given below for a better understanding of the function.
Example 1: When an array is given the output is false.
<!DOCTYPE html>
<html lang= "en" >
<head>
<meta charMap= "UTF-8" >
<meta name= "viewport"
content= "width=device-width, initial-scale=1.0" >
<title>Document</title>
<script src=
</script>
</head>
<body>
<script>
var obj= new Array(2);
obj.fill(5)
var isWeakMap= _.isWeakMap(obj);
console.log(isWeakMap)
if (isWeakMap)
console.log(`The ${obj} is the WeakMap of Javascript.`)
else
console.log(`The ${obj} is not the WeakMap of Javascript.`)
</script>
</body>
</html>
|
Output:
Example 2:
When a weak set is given it returns true.
<!DOCTYPE html>
<html lang= "en" >
<head>
<meta charMap= "UTF-8" >
<meta name= "viewport"
content= "width=device-width, initial-scale=1.0" >
<title>Document</title>
<script src=
</script>
</head>
<body>
<script>
var obj= new WeakMap();
var isWeakMap= _.isWeakMap(obj);
console.log(isWeakMap)
if (isWeakMap)
console.log(`The ${obj} is the WeakMap of Javascript.`)
else
console.log(`The ${obj} is not the WeakMap of Javascript.`)
</script>
</body>
</html>
|
Output:
Share your thoughts in the comments
Please Login to comment...