Computer >> Computer tutorials >  >> Programming >> Javascript

Set.entries() function in JavaScript


The entries() function of the Set returns an iterator object which holds the contents of the current Set. This iterator object returns a pair of values for each entry just like map (key and value). But here, instead of both key and value it returns the element of the set in the particular position.

Syntax

Its Syntax is as follows

setObj.entries()

Example

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      const setObj = new Set();
      setObj.add('Java');
      setObj.add('JavaFX');
      setObj.add('JavaScript');
      setObj.add('HBase');
      const entries = setObj.entries();
      document.write("<br>");
      for (let item of entries) {
         document.write(item);
         document.write("<br>");
      }
   </script>
</body>
</html>

Output

Contents of the Set after deletion:
Java,Java
JavaFX,JavaFX
JavaScript,JavaScript
HBase,HBase