From the course: Learning ECMAScript 6+ (ES6+)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Working with sets

Working with sets - JavaScript Tutorial

From the course: Learning ECMAScript 6+ (ES6+)

Start my 1-month free trial

Working with sets

- [Presenter] Sets are collections of values that can be of any type, but the rule with Sets is that each value must be unique. The API of this is a little similar to Map, but a little bit different as well. So when we create a new set, we're going to use the constructor and then we can make use of some functions on the Sets prototype. So the first thing we'll do here is we will add a book to our set, "Pride and Prejudice." And then let's go ahead and add "War and Peace" as well. Once we've done this, we can log books to our console. And you'll see that this is not quite like a regular object. It looks a little bit more like a map. We see a couple different entries here and both of these are on an index. So zero and one. We also have access to that dot size utility and dot size is going to say that there are two books in this set. Another method that we can use is dot has. So let's on line eight here, check to see if…

Contents