--- 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/Objectes_globals/Set/add ---
El mètode add() afegeix un nou element al final de l'objecte Set amb el valor especificat pel paràmetre.
mySet.add(valor);
Set.L'objecte Set.
addvar mySet = new Set();
mySet.add(1);
mySet.add(5).add("some text"); // crida en cadena
console.log(mySet);
// Set [1, 5, "some text"]
| Especificació | Estat | Comentaris |
|---|---|---|
| {{SpecName('ES6', '#sec-set.prototype.add', 'Set.prototype.add')}} | {{Spec2('ES6')}} | Definició inicial. |
{{CompatibilityTable}}
| Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Suport bàsic | 38 | {{CompatGeckoDesktop("13.0")}} | 11 | 25 | 7.1 |
| Característica | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Suport bàsic | {{CompatNo}} | 38 | {{CompatGeckoMobile("13.0")}} | {{CompatNo}} | {{CompatNo}} | 8 |
Set.prototype.add retornava undefined i per tant no es podien realitzar crides encadenades. Aquest problem ha estat resolt ({{bug(1031632)}}). Aquest comportament també es pot trovar al Chrome/v8 (problema).