Set() 构造函数
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Set()
构造函数创建 Set
对象。
尝试一下
语法
参数
返回值
一个新的 Set
对象。
示例
使用 Set
对象
js
const mySet = new Set();
mySet.add(1); // Set [ 1 ]
mySet.add(5); // Set [ 1, 5 ]
mySet.add(5); // Set [ 1, 5 ]
mySet.add("some text"); // Set [ 1, 5, 'some text' ]
const o = { a: 1, b: 2 };
mySet.add(o);
规范
Specification |
---|
ECMAScript Language Specification # sec-set-constructor |
浏览器兼容性
BCD tables only load in the browser