Set entries() JavaScript

The JavaScript Set entries() method gives an object of Set iterator that contains an array of [value, value] for each element. As there is no concept of key in set that’s why value and key are same.

Note: Iterator object maintains the insertion order.

Syntax:

setObj.entries()

Return:
A iterator object that contains an array of [value, value] for each element in the specified Set.

Example:

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

Output:

DIAMOND,DIAMOND
GOLD,GOLD
PLATINUM,PLATINUM
SILVER,SILVER
Please Share