Plain objects and arrays are not always the best collections. Collection Keys Ordered Use for Object strings/symbols insertion (mostly) records, JSON Map any value (objects too) insertion dictionaries, caches, frequent add/remove Set unique values insertion de-duplication, membership tests WeakMap objects only, weakly held no private data / metadata without memory leaks WeakSet objects only, weakly held no "has this object been seen?" flags Why Map over Object for dictionaries? Map has a reliable size, accepts any key type, has no prototype keys to collide with ("constructor"), and is faster for frequent insertions and deletions. Set operations Modern engines support union, intersection, difference and isSubsetOf directly on Set. Weak collections Entries in a WeakMap do not prevent their…
Key Takeaways
Use Map for dictionaries with dynamic or non-string keys.
Set gives O(1) membership checks and easy de-duplication.
Weak collections hold keys weakly — no memory leaks for metadata.
Convert with [...map], new Map(Object.entries(obj)) and Object.fromEntries(map).