JavaScript Code

JavaScript Set values()

Set values() method

values() method returns a new iterator object which contains values of elements from the Set object.

  • mySet is a Set of elements.
  • values is method name.

We can use a for loop to iterate over the iterator object, or use iterator methods like next(), etc.


1. Iterate over values of the fruits set.

const fruits = new Set(['apple', 'banana', 'cherry']);
for(let value of fruits.values()) {

Copyright @2022