在线文档教程

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"]

规范

SpecificationStatusComment
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Set.prototype.add' in that specification.StandardInitial definition.
ECMAScript Latest Draft (ECMA-262)The definition of 'Set.prototype.add' in that specification.Living Standard

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support38(Yes)13.0 (13.0)11257.1

FeatureAndroidChrome for AndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic supportNo support38(Yes)13.0 (13.0)No supportNo support8