Set delete() JavaScript JS

The JavaScript Set delete() method deletes or removes only the selected elements from the Set object.

Syntax:

setObj.delete(value)

Parameters:
value: It represents the value of the specified property to be deleted.

Return:
It returns true if specified element is deleted or removed successfully otherwise returns false.

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.delete("SILVER");  
document.write(jewels.size);  
</script>
</body>
</html>

Output:

DIAMOND
GOLD
PLATINUM
SILVER
3
Please Share