课程: JavaScript: Maps and Sets

The Map object defined

- [Instructor] Maps are an object type that was fairly recently introduced into JavaScript with ES2015. Object and Map are very similar, but they also have some key differences. Let's take a look at some of the ways that they're alike, and different to help you have a better understanding of how Map might fit into your code. Similar to Object, a Map contains key-value pairs. You can set the key-value pairs, get them, delete them, and check to see if a value is associated with a specific key. The Map object has slight differences that can make them extremely powerful and useful. Unlike an Object, a Map does not contain default keys. You have to set the keys in your Map. Additionally, a Map's keys are not limited to just a string or a symbol, they can be any value. Map also has a size property that allows you to easily determine the number of items your Map contains. One other important thing to keep in mind about Maps, is that you can not have duplicate keys in your key-value pairs. When you're ready to start using Map, you will use the constructor new Map to create a new Map object. Now that you have an idea of what makes Maps special, let's discuss how to create one and start utilizing the various methods and properties available on the Map object.

内容