Lesson 25. Maps

After reading lesson 25, you will

  • Know to create a Map
  • How to convert a plain object into a Map
  • How to add and access values on a Map
  • How to iterate the keys and values from a Map
  • How Maps are destructured
  • Understand when it makes sense to use a Map over an Object
  • Understand why it makes sense to use a WeakMap over a Map

Like Sets, Maps are a new type of object in JavaScript. Not to be confused with Array.prototype.map, which is a higher-order array method, Maps are another type of iterable that’s new to JavaScript in ES2015. A Map is a lot like a generic object in JavaScript with keys and values. But a Map can be iterated, whereas an object can’t. Plain objects are also limited to only being able to have string values as ...

Get Get Programming with JavaScript Next 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.