JavaScript – Create an Empty Set
To create an empty Set in JavaScript, create a new set using new Set()
and pass no arguments to the constructor. The new Set()
creates and returns an empty Set.
Syntax
The syntax to create an empty Set using Set() constructor is
</>
Copy
new Set()
Examples
In the following example, we create an empty set using Set() constructor.
index.html
<!DOCTYPE html>
<html lang="en">
<body>
<pre id="output"></pre>
<script>
//create set from array
var set1 = new Set();
var displayOutput = 'Set size : ' + set1.size;
document.getElementById('output').innerHTML += displayOutput;
</script>
</body>
</html>
Conclusion
In this JavaScript Tutorial, we learned how to create an empty Set in JavaScript using Set() constructor, with examples.