Javascript WeakMap get()

Introduction

The Javascript WeakMap get() method returns a value for a key from a WeakMap object.

wm.get(key);
Parameters Optional Meaning
keyNot. The key of the element to return from the WeakMap object.

Using the get method


let window = function() {};

var wm = new WeakMap();
console.log(wm);/*from  ww  w . j  a va 2 s  . c  o m*/
wm.set(window, 'foo');
console.log(wm);

let a = wm.get(window); // Returns "foo".
console.log(a);
a = wm.get('baz');  // Returns undefined.
console.log(a);



PreviousNext

Related