JavaScript WeakMap has() method

The has method of the JavaScript WeakMap determines if the specified key exists within the WeakMap instance. It yields true if the key is found, and false if it is not present.

Syntax

The syntax for the has method is expressed as follows:

Example

WeakMapObj.has(key)

Parameter

key - It represents the key to be searched.

Return

A Boolean value.

JavaScript WeakMap has method example

Let’s examine an example to ascertain if the WeakMap object includes the given key.

Example

<script>

var wm = new WeakMap();

var obj1 = {};

var obj2 = {};

var obj3= {};

wm.set(obj1, "jQuery");

wm.set(obj2, "AngularJS");

wm.set(obj3,"Bootstrap");

document.writeln(wm.has(obj2));

</script>

Output:

Input Required

This code uses input(). Please provide values below: