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.values()
  • 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.

Examples

1. Iterate over values of the fruits set.

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

Copyright @2022