ES6 set 中的键和值相同吗?

Ale*_*nik 8 javascript set ecmascript-6

我刚刚浏览了set的 MDN 文档,以及它是如何工作的,来到如何迭代 set 的部分,我看到了以下示例:

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

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

// 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);
Run Code Online (Sandbox Code Playgroud)

只是为了确认,这是否意味着使用 set 时键和值是相同的?

Jon*_*lms 7

Entrys() 方法返回一个新的 Iterator 对象,其中包含 Set 对象中每个元素的 [value, value] 数组,按插入顺序 [...]。

MDN 文档

所以不,集合根本没有键,但是.entries()让您相信映射和集合之间具有一致性。