--- title: Set.prototype.add() slug: Web/JavaScript/Reference/Global_Objects/Set/add translation_of: Web/JavaScript/Reference/Global_Objects/Set/add original_slug: Web/JavaScript/Referencia/Objetos_globales/Set/add ---
El método add()
añade un nuevo elemento con un valor específico al final del objeto Set
.
mySet.add(value);
Set
.El objeto Set
.
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 |
---|---|---|
{{SpecName('ES6', '#sec-set.prototype.add', 'Set.prototype.add')}} | {{Spec2('ES6')}} | Initial definition. |
{{SpecName('ESDraft', '#sec-set.prototype.add', 'Set.prototype.add')}} | {{Spec2('ESDraft')}} |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 38 | {{CompatGeckoDesktop("13.0")}} | 11 | 25 | 7.1 |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | 38 | {{CompatGeckoMobile("13.0")}} | {{CompatNo}} | {{CompatNo}} | 8 |
Set.prototype.add
returned undefined
and was not chainable. This has been fixed ({{bug(1031632)}}). The behavior can be found in Chrome/v8 as well (issue).