Tip 13 | Update Key-Value Data Clearly with Maps |
In this tip, you’ll learn how to use the Map object for key-value collections of frequently updated data.
In Tip 10, Use Objects for Static Key-Value Lookups , you learned that you should only use objects deliberately and not as a default collection. Now you’re going to get a chance to look at an alternative: Map.
Map is a special kind of collection that can do certain things very easily. The Mozilla Developer Network has a nice list of circumstances where Map is a better option for a collection than a plain object.[13] I encourage you to read the full list, but this tip examines two specific situations:
- Key-value pairs are frequently added or removed.
- A key isn’t a string.
In the next tip, you’ll ...
Get Simplifying JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.