Die add() Methode fügt ein neues Element mit dem angegebenen Wert an das Ende eines Set Objekts hinzu.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Syntax
mySet.add(value);
Parameter
value- Der hinzufügende Wert zu dem
SetObjekt.
Rückgabewert
Das Set Objekt.
Beispiele
Verwenden der add() Methode
var mySet = new Set();
mySet.add(1);
mySet.add(5).add('some text'); // chainable
console.log(mySet);
// Set [1, 5, "some text"]
Spezifikationen
| Spezifikation |
|---|
| ECMAScript (ECMA-262) Die Definition von 'Set.prototype.add' in dieser Spezifikation. |
Browserkompatibilität
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
add | Chrome Vollständige Unterstützung 38 | Edge Vollständige Unterstützung 12 | Firefox Vollständige Unterstützung 13 | IE
Teilweise Unterstützung
11
| Opera Vollständige Unterstützung 25 | Safari Vollständige Unterstützung 8 | WebView Android Vollständige Unterstützung 38 | Chrome Android Vollständige Unterstützung 38 | Firefox Android Vollständige Unterstützung 14 | Opera Android Vollständige Unterstützung 25 | Safari iOS Vollständige Unterstützung 8 | Samsung Internet Android Vollständige Unterstützung 3.0 | nodejs
Vollständige Unterstützung
0.12
|
Legende
- Vollständige Unterstützung
- Vollständige Unterstützung
- Teilweise Unterstützung
- Teilweise Unterstützung
- Siehe Implementierungshinweise.
- Siehe Implementierungshinweise.
- Benutzer muss dieses Feature explizit aktivieren.
- Benutzer muss dieses Feature explizit aktivieren.