Skip to content

JavaScript set values() method

  • by

JavaScript set values() method returns a new Iterator object that contains the values for each element in the Set object in insertion order.


Note: the values() method returns an iterator object, so we need to use the next() method to retrieve each value.

JavaScript set values() examples

Simple example code using the Set.prototype.values() method. The values() method on returns an iterator object containing the values in mySet. We then use the next() method on the iterator to retrieve each value in turn.

<!DOCTYPE html>
  <script >
    const mySet = new Set([1, 2, 3, 4, 5]);
    const iterator = mySet.values();


    console.log(; // 1
    console.log(; // 2
    console.log(; // 3
    console.log(; // 4
    console.log(; // 5



JavaScript set values() method

Get the values with iterator using the size property of Set

let i = 0;
while (i < myset.size) {

Do comment if you have any doubts or suggestions on the Js method topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *