课程: JavaScript: Maps and Sets

今天就学习课程吧!

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

Add values to your set

Add values to your set

- [Instructor] In order to construct your new set, you will need to reach for the method, add. The add method adds a new value to your set upending the specified value to the end of your object. In order to add values, we simply apply the set method to our existing set and pass in the value. This method can also be changed which will save you some room in your code. Let's move on to an example and see add in action. As we did with maps, we will revisit the same example with sets as we learn each of its methods in property. For our sets example, let's imagine that we're planning a surprise birthday party for our friend. We're going to utilize a set because we want to make sure we don't have any duplicate email addresses when we send out our invitations. Let's start by creating a new set, invites. Once created, let's add our emails to the set using the add method. We're going to save ourselves some typing and chain…

内容