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.
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.
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

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
