JavaScript Set values() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Instance method

Definition

set.values() returns an iterator that gives you every value of the Set, one by one, in the order the values were added. It is the method that for (const value of set) uses behind the scenes.

The iterator is not an array. To get an array, wrap it in Array.from() or spread it with [...set.values()]. The iterator is live and can be used only once.

Remember
set.values()

gives every value, in the order they were added
returns an iterator, not an array

Array.from(set.values())   → array
[...set.values()]          → array
An iterator can be used only once

Syntax

Call it on a Set. It takes no arguments and is usually used with for...of or Array.from().

JavaScript
const colors = new Set(["red", "green", "blue"]);

for (const value of colors.values()) {
  console.log(value);
}
// red
// green
// blue
CallWhat it does
set.values()An iterator of the values of the Set.
Array.from(set.values())Turn the values into an array.
Math.max(...set.values())Spread the values into a function call, for example to find the biggest number.
for (const value of set)The shortest way to loop. It uses the same iterator.

A standard JavaScript method (ES2015) on every Set, from Set.prototype. No import required. Siblings: add(), clear(), delete(), difference(), entries(), forEach(), has(), intersection(), isDisjointFrom(), isSubsetOf(), isSupersetOf(), keys(), symmetricDifference(), union(), [Symbol.iterator]().

Library declarations
JavaScript
// ECMAScript 2015 (ES6)
Set.prototype.values()

// returns: a Set Iterator of the values

Parameters

ParameterDescription
(none)This method takes no parameters. Call it as set.values().

Return Value

Return ValueDescription
Set IteratorAn iterator object. Each step gives { value: item, done: false }. When all values are used, it gives { value: undefined, done: true }. The iterator can be used only once.

JavaScript Examples

Example 1 — Loop Over the Values

Use values() in a for...of loop, and check that the default loop gives the same values.

JavaScript
const colors = new Set(["red", "green", "blue"]);

for (const value of colors.values()) {
  console.log("Value: " + value);
}

const plain = [];
for (const value of colors) {
  plain.push(value);
}
console.log("Plain loop: " + plain.join(", "));
Try It Yourself

How It Works

  1. Ask for the values. colors.values() gives an iterator, and for...of reads it from the first value to the last.
  2. Insertion order. The values come out in the order they were added to the Set.
  3. The plain loop is the same. for (const value of colors) uses values() automatically, so you get the same list with less typing.

Example 2 — Convert the Values to an Array

Turn the iterator into an array, change each value on the way, and find the biggest number.

JavaScript
const scores = new Set([30, 10, 20]);

const list = Array.from(scores.values());
console.log("List: " + list.join(", "));

const doubled = Array.from(scores.values(), (n) => n * 2);
console.log("Doubled: " + doubled.join(", "));

console.log("Biggest: " + Math.max(...scores.values()));
console.log("Spread length: " + [...scores.values()].length);
Try It Yourself

How It Works

  1. To an array. Array.from() reads the iterator and builds an array. The order stays the same as in the Set, it is not sorted.
  2. Change while converting. The second argument of Array.from() is a function that is applied to every value, so the numbers are doubled.
  3. Spread. ...scores.values() turns the values into separate arguments for Math.max(), and [...] builds a new array.

Example 3 — The Iterator Is Live and Used Once

Read one value, add a new value to the Set, and see that the iterator still reaches it. Then see what a finished iterator gives.

JavaScript
const set = new Set([1, 2]);
const iterator = set.values();

console.log("First: " + iterator.next().value);

set.add(3);
console.log("Rest: " + Array.from(iterator).join(", "));
console.log("Used up: " + Array.from(iterator).length);

console.log("Fresh iterator: " + Array.from(set.values()).length);
Try It Yourself

How It Works

  1. Read one value. The first next() gives 1. The iterator now waits at 2.
  2. Add a value. set.add(3) adds a value at the end. Because the iterator is live, it reaches 3 too, so the rest is 2, 3.
  3. Used up. The old iterator has no values left, so it gives an empty array. A fresh set.values() starts again and finds all 3 values.

Browser & Runtime Support

Set.prototype.values() is part of ES2015 (ES6), together with Set itself. Every current browser and Node.js has it.

✓ ES2015 · Widely supported

set.values()

Supported in Chrome 38+, Edge 12+, Firefox 37+, Safari 9+, Opera 25+ and Node.js 4+. Internet Explorer never got it.

ES2015 Standard since
Google Chrome 38+ · Desktop & Mobile
Full support
Microsoft Edge 12+ · Chromium based
Full support
Mozilla Firefox 37+ · Desktop & Mobile
Full support
Apple Safari 9+ · macOS & iOS
Full support
Opera 25+ · Chromium based
Full support
Samsung Internet Recent versions · Android
Supported
Android WebView 38+ · Chromium based
Supported
Node.js 4+ · Server runtime
Supported
Deno Recent versions · JavaScript runtime
Supported
Bun Recent versions · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
set.values() Excellent

Bottom line: Safe to use in every current browser and in Node.js. Only Internet Explorer needs special care.

Frequently Asked Questions

It returns an iterator that gives every value of the Set, one at a time, in the order they were added. It is not an array.
Use Array.from(set.values()), [...set.values()], or the shorter Array.from(set) and [...set]. All of them give the values in insertion order.
There is none for a Set. Set.prototype.keys and Set.prototype.values are the same function. values() is the clearer name for a Set.
No. After the last value has been read, the iterator stays finished. Call set.values() again to get a new iterator that starts from the first value.
No. for (const value of set) already uses the same iterator. Use values() when you need an iterator object itself, for example with next(), or to pass to another function.

Next: [Symbol.iterator]()

Learn about the special method that makes a Set work with for...of, spread and destructuring.

[Symbol.iterator]() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful