Set and Map
JavaScript Sets
Initialize a Set
const s = new Set()Add items to a Set
s.add('one')
s.add('two')Check if an item is in the set
Delete an item from a Set by key
Determine the number of items in a Set
Delete all items from a Set
Iterate the items in a Set
Initialize a Set with values
Convert to array
Convert the Set keys into an array
A WeakSet
JavaScript Maps
What is a Map
Before ES6
Enter Map
Add items to a Map
Get an item from a map by key
Delete an item from a map by key
Delete all items from a map
Check if a map contains an item by key
Find the number of items in a map
Initialize a map with values
Map keys
Weird situations you’ll almost never find in real life
Iterating over a map
Iterate over map keys
Iterate over map values
Iterate over map key, value pairs
Convert to array
Convert the map keys into an array
Convert the map values into an array
WeakMap
Last updated