From the course: JavaScript: Maps and Sets
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Add values to your set - JavaScript Tutorial
From the course: JavaScript: Maps and Sets
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
The Set object defined57s
-
(Locked)
Add values to your set3m 17s
-
(Locked)
Does Set have your value?3m 9s
-
Get your set size2m 2s
-
(Locked)
Delete and clear values in your set2m 46s
-
(Locked)
Iterate over values in a set2m 45s
-
(Locked)
Iterate over a set with entries2m 25s
-
(Locked)
Iterate over your set with forEach2m 29s
-
(Locked)
Solution: Sets 12m 8s
-
(Locked)
Solution: Sets 22m 35s
-
-
-