set.add
set.add
add()
方法用来向一个Set
对象的末尾添加一个指定的值。
语法
mySet.add(value
参数
value
必需。需要添加到Set
对象的元素的值。
返回值
Set
对象本身
示例
使用 add 方法
var mySet = new Set(
mySet.add(1
mySet.add(5).add('some text' // chainable
console.log(mySet
// Set [1, 5, "some text"]
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Set.prototype.add' in that specification. | Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262)The definition of 'Set.prototype.add' in that specification. | Living Standard | |
浏览器兼容性
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 38 | (Yes) | 13.0 (13.0) | 11 | 25 | 7.1 |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | No support | 38 | (Yes) | 13.0 (13.0) | No support | No support | 8 |