课程: JavaScript: Maps and Sets

今天就学习课程吧!

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

Remove key-value pairs with clear and delete

Remove key-value pairs with clear and delete - JavaScript教程

课程: JavaScript: Maps and Sets

Remove key-value pairs with clear and delete

- [Instructor] In this lesson, we're going to cover two map methods that remove key value pairs from your map, delete and clear. The first method we will discuss is delete. The delete method will remove a specified key value pair from your existing map. Like many other methods, this is straightforward and you'll pass a key in order to execute the operation. If the key value pair is successfully deleted it will return the Boolean value true. If the key pass does not match any key value pairs in the map, it will return false. Next, we have the clear method. The clear method removes all elements or key value pairs from a map. This method returns a value of undefined. However, you could confirm that your map was successfully cleared by logging its size which we learned about that property in the previous lesson. Looking at our meals example, we will first delete the dessert key because we have a cookie emoji as a key in our…

内容