课程: JavaScript: Maps and Sets

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Access a value with get

Access a value with get

- [Instructor] In our previous lesson, we learned how to construct a map using the method set. In this lesson, we're going to discuss how to retrieve values from our map using the get method. One of the really helpful things about the methods associated with map is that they're all very straightforward. Here we have the syntax forget map object dot get passing in the key. We retrieve the value from our key value pair by passing in a key as an argument to our get method. If the key exists, the value associated with that key is returned. If the key does not exist in the map, undefined is returned. Let's return to our previous meals example and use the get method. At this point, we've already built our map using set. And we want to get a value based on a specific key. We know that get will return a value. So let's go ahead and set that to a new variable that we will call cookie. Then I'll apply get to my existing meals map.…

内容