Are keys and values the same in ES6 set?

Viewed 510

I was just going through the MDN documentation for set , and how it works , coming to the part of how to iterate over a set , i saw the following examples:

// logs the items in the order: 1, "some text", {"a": 1, "b": 2} 
for (let item of mySet) console.log(item);

And

// logs the items in the order: 1, "some text", {"a": 1, "b": 2} 
for (let item of mySet.values()) console.log(item);

And

// logs the items in the order: 1, "some text", {"a": 1, "b": 2} 
//(key and value are the same here)
for (let [key, value] of mySet.entries()) console.log(key);

Just to confirm , does this mean that when using set the keys and values are the same ?

1 Answers

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

MDN docs

So no, Sets don't have keys at all, however .entries() lets you believe so for having consistency between Maps and Sets.

Related