Set add() JavaScript JS

The JavaScript Set add() method is used to add the new element with the specified value to the Set object. New object will be added to the end of the Set object.

Syntax:

setObj.add(value)

Parameters:
value: It represents the value of the element to be added in set object.

Return:
Modified set object.

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>");  }   
</script>
</body>
</html>

Output:

DIAMOND
GOLD
PLATINUM
SILVER
Please Share