Tip 14 Iterate Over Key-Value Data with Map and the Spread Operator

In this tip, you’ll learn how to iterate directly over key-value data in maps with either loops or the spread operator.

In the previous tip, you saw how maps are an improved key-value collection when you’re regularly adding or deleting items. As you saw, objects are very useful, but there are times when a map has distinct advantages. You can see those advantages on the Mozilla Developer Network.[16]

You’ve already explored several advantages pertaining to when keys are set. Now you’re going to explore another suggested usage for maps: collections that are iterated.

Objects are very frustrating to iterate over. In fact, there used to be no way to directly iterate over them. You ...

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.