Tuesday, July 28, 2026
HomeLanguagesJavascriptJavaScript Set keys() Method

JavaScript Set keys() Method

The set.keys() method is the same as the values() method. This means it returns the new iterator object that contains the value of each set in the insertion order. 

Syntax:

keys()

Parameter: This method does not take any parameters.

Return Type: It returns the new iterator object which holds the values in the set.

Example 1: In this example, we will see the use of keys in the set.

Javascript




let placeSet = new Set();
  
placeSet.add("America");
placeSet.add("England");
placeSet.add("Chicago");
  
const setIterator = placeSet.keys();
  
console.log(setIterator);


Output:

[Set Iterator] { 'America', 'England', 'Chicago' }

Example 2: In this example, we will see the keys() method which returns the set iterator.

Javascript




const set1 = new Set();
  
set1.add('0');
set1.add(1);
set1.add(1);
  
const iterator1 = set1.keys();
console.log(iterator1);


Output

[Set Iterator] { '0', 1 }

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

Supported Browser:

  • Chrome 38
  • Edge 12
  • Firefox 24
  • Opera 25
  • Safari 8
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!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6973 POSTS0 COMMENTS