DEV Community

loading...

Discussion on: When You Should Use JavaScript Maps over Objects

Collapse
vsaravanan profile image
Viswanathan Saravanan

Excellent points. It was asked in one my interview. I didn't know until I read this article

• Only strings or symbols can be used as keys
• Own object properties might collide with property keys inherited from the prototype (e.g. toString, constructor, etc).
• Objects cannot be used as keys
These limitations are solved by maps.
Moreover, maps provide benefits like being iterators and allowing easy size look-up.Objects are not good for information that’s continually updated, looped over, altered, or sorted.

Use objects the vast majority of the time, but if your app needs one of these extra bits of functionality, use map.