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.
Log in to continue
We're a place where coders share, stay up-to-date and grow their careers.
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.