The Javascript WeakMap has()
method checks whether a key-value pair exists in the WeakMap object or not.
wm.has(key);
Parameters | Optional | Meaning |
---|---|---|
key | Not | The key of the element |
It returns true if an element with the key exists in the WeakMap object; otherwise false.
let window = function() {}; var wm = new WeakMap(); wm.set(window, 'foo'); console.log(wm);/*w ww .j a v a 2s . c om*/ let a = wm.has(window); // returns true console.log(a); a = wm.has('baz'); // returns false console.log(a);