Set add() JavaScript JS

The JavaScript Set add() method is used to add the new element with the specified value to the Set object. A 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 to a 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>
Please follow and like us:
Content Protection by DMCA.com