Set.prototype.entries()

Set 实例的 entries() 方法返回一个新的 设置迭代器 对象,该对象包含此集合中每个元素的 [value, value] 数组(按插入顺序排列)。对于 Set 对象,没有像 Map 对象中那样的 key。但是,为了保持 API 与 Map 对象相似,这里每个条目的键和值都具有相同的值,因此返回数组 [value, value]

¥The entries() method of Set instances returns a new set iterator object that contains an array of [value, value] for each element in this set, in insertion order. For Set objects there is no key like in Map objects. However, to keep the API similar to the Map object, each entry has the same value for its key and value here, so that an array [value, value] is returned.

Try it

语法

¥Syntax

js
entries()

参数

¥Parameters

没有任何。

¥None.

返回值

¥Return value

新的 可迭代的迭代器对象

¥A new iterable iterator object.

示例

¥Examples

使用条目()

¥Using entries()

js
const mySet = new Set();
mySet.add("foobar");
mySet.add(1);
mySet.add("baz");

const setIter = mySet.entries();

console.log(setIter.next().value); // ["foobar", "foobar"]
console.log(setIter.next().value); // [1, 1]
console.log(setIter.next().value); // ["baz", "baz"]

规范

Specification
ECMAScript Language Specification
# sec-set.prototype.entries

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看