Set clear() JavaScript

The JavaScript Set clear() method clears or remove all the elements from the Set object.

Syntax:

setObj.clear()

Example:

<!DOCTYPE html>
<html>
<body>
<script>  
var jewels = new Set();  
jewels.add("DIAMOND").add("GOLD").add("PLATINUM").add("SILVER");  
for (let i of jewels) {  
document.write(i+"<br>");  }
jewels.clear();  
document.write(jewels.size);  
</script>
</body>
</html>

Output:

DIAMOND
GOLD
PLATINUM
SILVER
0
Please Share