This is a new technology, part of the ECMAScript 2015 (ES6) standard.
This technology's specification has been finalized, but check the compatibility table for usage and implementation status in various browsers.
El mètode add() afegeix un nou element al final de l'objecte Set amb el valor especificat pel paràmetre.
Sintax
mySet.add(valor);
Paràmetres
- valor
- Obligatori. El valor de l'element que s'afegirà a l'objecte
Set.
Valor retornat
L'objecte Set.
Exemples
Utilitzar el mètode add
var mySet = new Set();
mySet.add(1);
mySet.add(5).add("some text"); // crida en cadena
console.log(mySet);
// Set [1, 5, "some text"]
Especificacions
| Especificació | Estat | Comentaris |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Set.prototype.add' in that specification. |
Standard | Definició inicial. |
Compatibilitat amb navegadors
| Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Suport bàsic | 38 | 13.0 (13.0) | 11 | 25 | 7.1 |
| Característica | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Suport bàsic | Not supported | 38 | 13.0 (13.0) | Not supported | Not supported | 8 |
Notes específiques per al Firefox
- En les versions anteriors al Firefox 33 (Firefox 33 / Thunderbird 33 / SeaMonkey 2.30),
Set.prototype.addretornavaundefinedi per tant no es podien realitzar crides encadenades. Aquest problem ha estat resolt (errada 1031632). Aquest comportament també es pot trovar al Chrome/v8 (problema).