Setting and deleting entries from WeakMap

We've seen how to use Maps in a variety of situations. There is another new class in ECMAScript that behaves in a very similar way, but has some helpful properties. The WeakMap, like Map, is a key-value data structure.

In this recipe, we'll take a look at how to add and remove elements from a WeakMap with the set and delete methods. And we'll also see how they differ from the Map class.

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.