课程: JavaScript: Maps and Sets

今天就学习课程吧!

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

Delete and clear values in your set

Delete and clear values in your set - JavaScript教程

课程: JavaScript: Maps and Sets

Delete and clear values in your set

- [Instructor] In order to delete and clear values from a set, we can reach for methods of the same name. The first method is delete. This will remove a single value from a set. In order to delete a value from a set, you will simply apply the delete method to your set and pass in the value that you'd like to delete. It's that simple and almost identical to what we did with maps. Moving onto the clear method, this method will remove all of the values from a set. You may remember this from our maps discussion as well. To clear your set, you simply apply the clear method to your existing set. It does not take any arguments. If you want to check that your set was cleared successfully, you could use the size property to make sure it's back to zero. Let's take a look at our invites example and see these methods in action. We decided that we no longer want to invite Jane to our party, so we decide to delete her invite.…

内容