Horje
What is the use of the Values method in JavaScript Sets ?

In JavaScript Sets, the values() method is used to return a new iterator object that contains the values for each element in the Set, in insertion order. The iterator object follows the iterable protocol, allowing you to loop through the values using methods like next().

Syntax:

mySet.values()
  • mySet: The Set for which you want to obtain an iterator for its values.

Example: Below is an example of a value method

Javascript

let myset = new Set();
 
// Adding new element to the set
myset.add("California");
myset.add("Seattle");
myset.add("Chicago");
 
// Creating a iterator object
const setIterator = myset.values();
 
// Getting values with iterator
console.log(setIterator.next().value);
console.log(setIterator.next().value);
console.log(setIterator.next().value);

Output

California
Seattle
Chicago



Reffered: https://www.geeksforgeeks.org


JavaScript

Related
How to Create an Empty Map in JavaScript ? How to Create an Empty Map in JavaScript ?
How to Check the Size of a JavaScript Map ? How to Check the Size of a JavaScript Map ?
What is the use of the Map.prototype.keys method in JavaScript Maps ? What is the use of the Map.prototype.keys method in JavaScript Maps ?
What is the use of the Map.prototype.clear method in JavaScript Maps ? What is the use of the Map.prototype.clear method in JavaScript Maps ?
What is the use of the Get method in Maps in JavaScript ? What is the use of the Get method in Maps in JavaScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12