JavaScript Set values() method - JavaScript Tutorial

JavaScript Set values() method

BLUF: This tutorial on JavaScript Set values() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Set values() method

Understanding JavaScript Set values() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The values method of the JavaScript Set returns a new Set iterator object. This iterator object encompasses the values of each element within the Set. It preserves the order of insertion.

Syntax

The syntax for the values method is as follows:

Example

setObj.values()

Return

A new object of set iterator.

JavaScript Set values method example

In this section, we will explore the values method by examining multiple examples.

Example 1

Let's see a simple example of values method.

Example

<script>

var set = new Set();

set.add("jQuery");

set.add("AngularJS");

set.add("Bootstrap");

var itr=set.values();

document.writeln(itr.next().value+"<br>");

document.writeln(itr.next().value+"<br>");

document.writeln(itr.next().value);

 </script>

Output:

Output

jQuery

AngularJS

Bootstrap

Example 2

Let's see the same example using for loop.

Example

<script>

var set = new Set();

set.add("jQuery");

set.add("AngularJS");

set.add("Bootstrap");

var itr=set.values();

for(i=0;i<set.size;i++)

  {

document.writeln(itr.next().value+"<br>");

  }

 </script>

Output:

Output

jQuery

AngularJS

Bootstrap

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience