Set()
构造函数创建 Set
对象。
¥The Set()
constructor creates Set
objects.
¥Syntax
new Set()
new Set(iterable)
注意:Set()
只能与 new
一起构建。尝试在没有 new
的情况下调用它会抛出 TypeError
。
¥Note: Set()
can only be constructed with new
. Attempting to call it without new
throws a TypeError
.
¥Parameters
iterable
Optional
-
如果一个 可迭代对象 被传递,它的所有元素将被添加到新的 Set
中。
如果不指定该参数,或者其值为 null
,则新的 Set
为空。
¥Return value
一个新的 Set
对象。
¥A new Set
object.
¥Using the Set
object
const mySet = new Set();
mySet.add(1);
mySet.add(5);
mySet.add(5);
mySet.add("some text");
const o = { a: 1, b: 2 };
mySet.add(o);
BCD tables only load in the browser