![]() |
VOOZH | about |
The Javascript Set constructor is used to create Set objects. It will create a set of unique values of any type, whether primitive values or object preferences. It returns the new Set object. It mainly helps in creating a new set of objects which contains unique elements.
new Set()
new Set(iterable)
This method accepts a single parameter that is described below:
Example 1: In this example, we will see how to create a new Set object.
Output:
Set(5) { 'California', 'India', 'Russia', 10, { a: 1, b: 8 } }Example 2: In this example, we will see that set takes only a unique value.
Output:
Set(4) { 'California', 'India', 10, { a: 5 } }In this example, we have added two times "California" and 10 but it creates a set with unique values.
We have a complete list of Javascript Set methods, to check those please go through this Sets in JavaScript article.