JavaScript Set keys()
Example
// Create a Set
const letters = new Set(["a","b","c"]);
// Get the Values
const myIterator = letters.keys();
// List the Values
let text = "";
for (const x of myIterator) {
text += x;
}
Try it Yourself »
More Examples Below !
Description
The keys()
method returns an Iterator object with the values in a set.
The keys()
method does not change the original set.
Note
Since a set has no keys, the keys()
method returns the same as values()
.
This makes JavaScript sets compatible with JavaScript maps.
Syntax
set.keys()
Parameters
NONE |
Return Value
Type | Description |
Iterator | An iterable object with the values of the set. |
More Examples
Looping the set.keys() directly:
// Create a Set
const letters = new Set(["a","b","c"]);
// List all Elements
let text = "";
for (const x of letters.keys()) {
text += x;
}
Try it Yourself »
Browser Support
set.keys()
is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported in all modern browsers since June 2017:
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |
set.keys()
is not supported in Internet Explorer.