From the course: JavaScript: Maps and Sets
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Solution: Maps 1 - JavaScript Tutorial
From the course: JavaScript: Maps and Sets
Solution: Maps 1
(upbeat music) - [Instructor] Welcome to your first CoderPad challenge for maps. For this particular challenge, we're going to set up a map and then we're going to determine the map size. So below in our test code, you can see that we already have a new map of fruit inventory set up for us. So now we just need to add individual items to that map. And then we're going to return the size of a map to test our solution. So the first thing that I'll do is start with our fruit inventory and then we're going to use the map method set to add each item in the inventory. So our first value here is going to be the key, which will be apples, and then the value of 10. So we'll just go right down the line with each of these items and add it to our map. So oranges 15 value, and then bananas right after. And that has a value of 20. Excellent. So we have all our items added to the map. Now we need to determine the size. So we're going to use the size property to do so. So fruit inventory, spell that…
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
-
-
-
-
-