So then the next modern feature I want to talk about are sets. And sets are a new data structure in the object category, which means they're a reference type, and they allow us to store a list of any kind of unique values. And by that I mean that in any given set a certain value can only be present once. So these are a bit like an array, but they don't allow duplicates, whereas an array would allow duplicate values inside it. Now that is a massive oversimplification because arrays and sets have totally different methods and properties from one another. But on the surface that is the big difference. So to demonstrate this, we're going to work through a couple of different examples. First of all, notice this. I've got a names array right here. That's just a normal array with strings. But notice we have two rows inside this. So that is duplicate values, right? If I save this, we'll log in it to the console. By the way, if I save it, we can preview it. And that's perfectly valid. We can have duplicate values inside an array. Now, if I was to pass this array into a set, then it wouldn't allow duplicate values. So let me demonstrate this. Now what I'm going to do is say const and then names set and set that equal to a new set. Now there's no shorthand way of creating sets like for arrays, we can use square brackets. When we're creating sets, we have to use the new keyword and the set constructor. So this creates a brand new empty set. But like I said, we can pass an array into the set, which is going to then do its magic on it and eliminate any duplicate values. So let me just copy this array now and paste it in here and save it. Now if we were to log this to the console. So I'm going to say console, dot log and then names set and save this. Let's preview this. And now we can see we have this set. It's different syntax from an array. We use curly braces here and inside we can see we only have one Ryu, so it's deleted essentially one of the riots because we are not allowed duplicates in a set. Okay. So that's the big major difference. Now we could also, if you wanted to just pass the names array directly into a set without explicitly writing the whole array. So let me just comment this out and then come down here and I'll say const names set is equal to a new set and pass in the names array. So let me take that and paste it in here. That does exactly the same thing. Save it and we can still see that set right here. So this idea of sets is good. If we ever have an array of data and we want to eliminate any kind of duplicates from that array of data so we could pass it into a set, but then ultimately we're left with a set. What if we want to eliminate duplicates but be left with an array? Well, what we could do is something like this. I'm going to use the spread syntax on the names set. So if we say const unique names is equal to a new array, and then inside the array I'm going to use the spread syntax and then say names set so we can use the spread syntax in front of a set, which is this thing. Remember, this set takes in this array and we get a set of values which are unique based on the array. Now we're spreading those values right here, using the spread syntax back into a new array. So now if we were to log this to the console console dot log, and then we want to log unique names like so and save it, then we can see over here now we have an array of unique names. So it took a couple of steps. First, we had to put it into a set, then spread that set into a new array. Now we can shorten this whole process by doing this in one single line. So let me now just comment these things out and we'll comment out this. And now what I want to do is say const unique names is now equal to an array. And inside this array we're going to use the spread syntax on a new set. And inside that set we're just going to pass in the names array. Or we could pass this in directly. Doesn't really matter. We're passing in the names array, so that makes a set. Then it spreads those values right here into this new array. And that's going to do exactly the same thing. So if I save it now, we can see this brand new array which has unique values. Awesome. Now, I did say before that it was an oversimplification to say that a set was just like an array, but only allows unique values. And it's an oversimplification because sets have their own unique set of methods and properties, so we can't use a length property on a set or a push method. Instead, we have different methods and different properties. So what if we now create a new set? Let me come down here and say const and we'll call this ages. To set it equal to a new set. Now, there's nothing in there to begin with. We're making a brand new set. What if we want to now add some values to this set? Well, we could say ages and then use a method called Add. And then inside the parentheses we say what value we want to add to the set so I can say 20. So now if I come down here and say console dot log ages, then we're going to see this set is just got one value inside it. Now I can do the same thing down here. I could add another value. So let me now say 25 and save it. And now we can see those two values. Now these are chainable, meaning we can chain them together. I could do add and then another add and this would be 30. Save that. And now we get that as well. So we can chain these add methods together. Now, what if I try to add a value that's already in it like this? Well, let's try that. I'm going to say ages dot add and then 25, which we already have. Save that and come over here and it doesn't put it in. It knows that it already has a 25 in the set because we added it here and it disregards this one that we tried to add to it later. So that's how we add elements to a set. What if we want to remove one? Well, we just say ages, then delete then the value we want to remove. Now, since all the values inside a set are going to be unique, we're never at the risk of removing multiple values by passing in the value we want to remove. So we could just say 25 and it's going to find that value and take it away from the set. So now we can see we're just left with 20 and 30. Now I said it also has different properties and we can't use the length property like we can on an array to find out the length of the set. But what we can do is use ages dot size and this will pretty much do the same thing. It tells us the size of the set we can see right here too. Now there's also another method we can use called Has, and that's to check if this set has a certain value inside it. So say for example, I could say console, dot log and then inside ages Dot has and I'm going to check if it has the value 30. Now this is going to return a boolean either true or false. So let me save that and preview and we can see that this is true because 30 is inside the set. And if I do a different one, I'm going to say ages Dot has and then I'm going to say 25, save that and we should get false because it doesn't have 25. Initially we added 25, but then we delete it. Then we see if it has it so it doesn't. Okay, so that's a couple of different methods and properties we can use on sets. There is one more I'm going to show you and that is how to clear out the set. So to remove all of the values inside it. So to do that we say ages dot clear and that's going to remove all of the values from the set. And we can say console dot log now ages to verify that save and now we can see there's nothing in the set. Okay So finally sets are iterable, meaning we can use the for each method on them. So if I wanted to cycle through a set, I could come down here and in fact, what I'm going to do is just copy some data from my repo over here and you can see this is just a simple set called ninjas. So we set it to a new set and we're passing in an array right here. We can do that. We've seen that before. So inside this array we have three objects. Sean 30. Krystal 29 and Chun-li 32. So they're all unique. That's fine. But what if I want to iterate this set? What if I want to cycle through it? Well, I can do that by saying ninjas dot for each and then fire in a callback function for each individual ninja inside that set. And we can just say console dot log the ninja dot name and also the ninja dot age. So let me now save this and preview and we can see over here that this works fine. So there we go. My friends, that is sets in a nutshell. On the surface, they're a bit like an array, but they only allow unique values. But they also come with their own host of methods and properties as well.