← Reference

Map and Set

Map, Set, WeakMap, and WeakSet collection types.

Map

Store key-value pairs with any type of key, maintaining insertion order.

new Map()

Map.prototype.clear()

Removes all key-value pairs from a Map object, resetting its size to zero.

map.clear()

Map.prototype.delete()

Remove a key-value pair from a JavaScript Map with delete().

map.delete(key)

Map.prototype.entries()

Iterate over a JavaScript Map as [key, value] pairs.

map.entries()

Map.prototype.forEach()

Execute a function for each key-value pair in a JavaScript Map using the forEach() method.

map.forEach(callbackFn, thisArg)

Map.prototype.get()

Retrieve values from a Map by key. Understand how get() returns undefined for missing keys and why has() is essential for robust Map operations.

map.get(key)

Map.prototype.has()

Check if a key exists in a JavaScript Map using the has() method.

map.has(key)

Map.prototype.keys()

Get all keys from a JavaScript Map using the keys() iterator method.

map.keys()

Map.prototype.set()

Add or update a key-value pair in a JavaScript Map using the set() method.

map.set(key, value)

Map.prototype.values()

Get all values from a JavaScript Map using the values() iterator method.

map.values()

Set

A collection of unique values with O(1) lookup performance, introduced in ES6.

Set.prototype.add()

Add a value to a JavaScript Set and learn how it enforces uniqueness through strict equality.

set.add(value)

Set.prototype.clear()

Remove all elements from a JavaScript Set instantly with clear(). Learn when to use it versus creating a new Set.

set.clear()

Set.prototype.delete()

Remove a value from a JavaScript Set using the delete() method.

set.delete(value)

Set.prototype.entries()

Iterate over Set entries using the entries() method in JavaScript.

set.entries()

Set.prototype.forEach()

Execute a function for each value in a JavaScript Set using the forEach() method.

set.forEach(callbackFn, thisArg)

Set.prototype.has()

Check if a value exists in a JavaScript Set using the has() method.

set.has(value)

Set.prototype.keys()

Return a new Set Iterator object that contains the values for each element in the set, in insertion order. Learn how keys() is an alias for values() and exis...

set.keys()

Set.prototype.size

Get the number of unique elements in a JavaScript Set with the size property.

set.size

Set.prototype.values()

Iterate over Set values using the values() method in JavaScript.

set.values()

WeakMap

WeakMap is a collection of key-value pairs where keys are objects and values can be any type. Unlike Map, it does not prevent garbage collection of its keys.

new WeakMap([entries])

WeakSet

WeakSet is a JavaScript collection that stores object references weakly, allowing automatic garbage collection when objects are no longer referenced elsewhere.

new WeakSet([iterable]) | weakset.add(value) | weakset.delete(value) | weakset.has(value)