From the course: JavaScript: Maps and Sets
The Map object defined - JavaScript Tutorial
From the course: 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.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
The Map object defined1m 23s
-
(Locked)
Build your Map object with the set method4m 41s
-
(Locked)
Access a value with get3m 51s
-
(Locked)
Does the map have your key?3m 4s
-
(Locked)
Determine map size2m 6s
-
(Locked)
Remove key-value pairs with clear and delete4m 23s
-
(Locked)
Map: Keys and values methods5m 44s
-
(Locked)
Map contents with the entries method2m 32s
-
(Locked)
Loop over a map with forEach2m 38s
-
(Locked)
Group entries with groupBy3m 22s
-
(Locked)
Solution: Maps 12m
-
(Locked)
Solution: Maps 21m 32s
-
-
-
-
-