Friday, September 5, 2025
HomeLanguagesJavascriptJavaScript Set entries() Method

JavaScript Set entries() Method

The Set.entries() method returns a new Iterator object that contains an array of [value, value] for each element in the Set object, in the order of their insertion. Although a Set does not contain key-value pairs, to keep similarities with the map.entries() method, it will return key-value pairs where both key and value will have the same value.

Syntax:

mySet.entries()

Parameters: This method does not accept any parameters.

Return Value: The entries() method returns a new Iterator object that contains an array of [value, value] for each element in the Set object, in insertion order.

Example 1:

Javascript




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


Output:

[ 'California', 'California' ]
[ 'Seattle', 'Seattle' ]
[ 'Chicago', 'Chicago' ]

Example 2:

Javascript




let myset = new Set();
 
// adding new elements to the set
myset.add("California");
myset.add("Seattle");
myset.add("Chicago");
 
// Creating a iterator object
const setIterator = myset.entries();
 
for (const entry of setIterator) {
    console.log(entry);
}


Output:

[ 'California', 'California' ]
[ 'Seattle', 'Seattle' ]
[ 'Chicago', 'Chicago' ]

Supported Browsers:

  • Chrome 38 and above
  • Edge 12 and above
  • Firefox 24 and above
  • Opera 25 and above
  • Safari 8 and above

We have a complete list of Javascript Set methods, to check those please go through this Sets in JavaScript article.

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.  

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6636 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11865 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7026 POSTS0 COMMENTS
Thapelo Manthata
6703 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS