Map and Set
Map is a key-value store with any key type and insertion-order iteration. Set stores unique values with fast membership testing.
Map is a key-value store with any key type and insertion-order iteration. Set stores unique values with fast membership testing.
const map = new Map();
map.set("key", 1); map.set({ id: 1 }, "obj key");
map.size; // 2
const set = new Set([1, 2, 2, 3]); // Set {1,2,3}
set.has(2); // true
const unique = [...new Set([1,1,2,3,3])]; // [1,2,3]
// WeakMap/WeakSet — keys weakly held (GC-able)
const cache = new WeakMap();
Use Set to deduplicate arrays: [...new Set(arr)] is idiomatic and fast.
More in JavaScript