Set forEach() JavaScript

The JavaScript Set forEach() method executes the specified function once for each value.

Syntax:

setObj.forEach(callback(currentValue, currentKey, Set))
{ 
  // code to be executed 
}

Parameters:
callback: It represents the function to be executed for each element, taking three arguments: (currentValue, currentKey, and set).

thisArg: It represents this keyword for the function.

Example:

<!DOCTYPE html>
<html>
<body>
<script>
var jewels = new Set();
jewels.add("DIAMOND").add("GOLD").add("PLATINUM").add("SILVER");
var gems= jewels.entries();
jewels.forEach(function display(i,set)
{
document.writeln(i+"<br>");
})
</script>
</body>
</html>