![]() |
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. Syntax:new Set() Parameters:This method accepts a single parameter that is described below:
Return Value:
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. Supported Browsers:
JavaScript Set() Constructor- FAQsWhat does the Set constructor do in JavaScript?
Can a Set contain duplicate values?
Can you use the Set constructor with WeakSet?
How does the Set constructor handle initial values?
What is the most common use of the |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |