Two data structures that solve problems objects and arrays can't — and when you should reach for them.
For a while, I thought JavaScript only had two ways to store data: objects (key-value pairs) and arrays (ordered lists). They handle most situations, so I never questioned whether there was something better.
Then I ran into two problems that made me realize their limitations:
Problem 1: I needed an object where the keys were other objects , not just strings. Regular objects can't do that — every key gets converted to a string.
Problem 2: I needed an array with no duplicates. I kept adding values and then manually checking "wait, is this already in there?" before each insertion.
Both problems have clean solutions: Map and Set .…