Set.prototype.values()

set.values()
Returns: Iterator · Updated March 13, 2026 · Map and Set
set values iteration

The values() method returns a new Iterator containing all the values in the Set.

Syntax

set.values()

Examples

Using values() to iterate

const fruits = new Set(['apple', 'banana', 'cherry']);

for (const fruit of fruits.values()) {
  console.log(fruit);
}
// apple
// banana
// cherry

Converting to Array

const set = new Set([1, 2, 3, 4, 5]);

// Using spread operator
const arr1 = [...set.values()];
console.log(arr1);
// [1, 2, 3, 4, 5]

// Using Array.from
const arr2 = Array.from(set.values());
console.log(arr2);
// [1, 2, 3, 4, 5]

Processing Set values

const prices = new Set([10, 20, 30, 40]);

// Double each value
const doubled = [...prices.values()].map(v => v * 2);
console.log(doubled);
// [20, 40, 60, 80]

// Sum all values
const sum = [...prices.values()].reduce((a, b) => a + b, 0);
console.log(sum);
// 100

Finding specific values

const tags = new Set(['javascript', 'python', 'rust', 'go']);

// Find values longer than 6 characters
const longNames = [...tags.values()].filter(t => t.length > 6);
console.log(longNames);
// ['javascript', 'python']

Practical: unique word counting

const text = 'the quick brown fox jumps over the lazy dog';
const words = new Set(text.split(' '));

const wordCount = [...words.values()].length;
console.log(wordCount);
// 8

Using iterator directly

const set = new Set(['a', 'b', 'c']);
const vals = set.values();

console.log(vals.next().value);
// 'a'
console.log(vals.next().value);
// 'b'
console.log(vals.next().value);
// 'c'
console.log(vals.next().done);
// true

Chaining array methods

const numbers = new Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

const result = [...numbers.values()]
  .filter(n => n % 2 === 0)
  .map(n => n * n);

console.log(result);
// [4, 16, 36, 64, 100]

See Also