Javascript WeakMap delete()

Introduction

The Javascript WeakMap delete() method removes the element from a WeakMap object.

wm.delete(key);
Parameters Meaning
keyThe key of the key-value pair to remove from the WeakMap object.

It returns true if an element has been removed successfully.

It returns false if the key is not found in the WeakMap or if the key is not an object.

var wm = new WeakMap();

let window = function() {};

wm.set(window, 'foo');

console.log(wm);// w  ww . j a v a  2  s .  c o  m

let a = wm.delete(window);
console.log(a);
console.log(wm);

a = wm.has(window);
console.log(a);



PreviousNext

Related