课程: JavaScript: Maps and Sets

今天就学习课程吧!

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

Does the map have your key?

Does the map have your key?

- [Instructor] The next Map method that we're going to discuss is the has method. This method returns a Boolean value, true or false, if a value associated with the provided key exists. The syntax as we have seen already is clear. We apply the has method to a Map and pass the key of the value that we're looking for in the Map. The Map methods has and get are very similar. The key distinction is that get returns a value associated with the key and has returns a Boolean indicating whether or not a value is associated with the provided key. Returning to our meals Map, we have a very similar example from the last lesson. We have replaced get with has, and we see that now we're getting Boolean values. Does our meals Map have a value associated with the key cookie emoji? True. Does our meals Map have a value associated with the key donut emoji? False. Let's go to the code and try an example together. Keeping with our to-do…

内容