Set.values() function in JavaScript


The values() function of the Set returns an iterator object which holds the values of the current Set object.The next() method returns the next element in the iterator object.

Syntax

Its Syntax is as follows

setObj.values()

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      const setObj = new Set();
      setObj.add('Apples');
      setObj.add('Oranges');
      setObj.add('Bananas');
      setObj.add('Grapes');
      var valuesObject = setObj.values();
      for(i=0; i<setObj.size; i++) {
         document.write(valuesObject.next().value);
         document.write("<br>");
      }
   </script>
</body>
</html>

Output

Apples
Oranges
Bananas
Grapes

Updated on: 25-Jun-2020

737 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements