You Complete Guide To Set Object In Javascript 
Tags: javascript, typescript, webdev, tutorial
Published: 2021-07-26 01:18:12

Hi everybody, I'm [Aya Bouchiha](https://t.me/AyaBouchiha), on this amazing day, we will talk about **all Set Methods and Properities** like *has()*, *add()*, *size*.

## Definition of a Set 

**Set**: is a collection of items and a built-in object, which stores only unique values.

## Set Constructor

![Aya Bouchiha Set Constructor](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6wddlmk7kgu77jifzunh.png)

## Iteration over a Set using For of loop

![Aya Bouchiha Set in Javascript](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2k2itodcxq3dd0p38xr.png)

## Size Property

**size**: is a set property that returns the length of the unique items in a specified set.

![Aya Bouchiha Size properity](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xmaq7e43w4l4rh50slxq.png)

## Set Methods

### Set.prototype.add()

**add(valueToAdd)**: is a set method that lets you add a new element to the specified Set.

![Aya Bouchiha Set Methods](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j3cx51i841zsk18zc0ll.png)
 
  
### Set.prototype.delete()

**delete(valueToDelete)**: is a set method that lets you  remove an element in a specified Set.

![Aya Bouchiha Set Methods (33)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4yzm7d5w0hruuj8ow56y.png)
  
## Set.prototype.clear()

**clear()**: means deleting all set elements.

![Aya Bouchiha Set Methods](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1lzwmpuo4vv00te29853.png)

### Set.prototype.has()

**has(valueToCheck)**: cheks if the given value exists in a set.

![Aya Bouchiha Set Methods](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b38xh55k4c8zwjwia28p.png)
  

### Set.prototype.entries()

**entries()**: returns an array(*iterator*) [val, val] for each item in the specified Set.

![Aya Bouchiha Set Methods](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r8xkvndshzfjj250v2i0.png)

### Set.prototype.values()

**values()**: like *keys()*, It returns a new iterator object which contains the values for each element in the specified Set.

![Aya Bouchiha Set Methods](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jle52cfa0s37vri3scwi.png)

### Set.prototype.forEach()

**forEach(callback)**: this Set method invokes a callback for each element in the specified Set.

![Aya Bouchiha Set Methods](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sexbcdpx5m9jnet7yok9.png)

#### Summary

+ **size**:returns the length of the unique items in a specified set.
+ **add(valueToAdd)**: lets you to add a new element to the specified Set.
+ **delete(valueToDelete)**:lets you  remove an element in a specified Set.
+ **clear()**: delete all Set elements.
+ **has(valueToCheck)**: cheks if the given value exists in a set.
+ **entries()**: returns an array(*iterator*) [val, val] for each item in the specified Set.
+ **values()**: returns a new iterator object which contains the values for each element in the specified Set.
+ **forEach(callback)**: invokes a callback for each element in the specified Set.

### References
+ [www.w3schools.com](www.w3schools.com)
+ [www.developer.mozilla.org](https://developer.mozilla.org/en-US/docs/Web/JavaScript)

Have a great day!

+ email:developer.aya.b@gmail.com
+ telegram: [Aya Bouchiha](https://t.me/AyaBouchiha)