Die delete() Methode entfernt das angegebene Element aus einem Set Objekt.
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.delete(value);
Parameter
value- Der zu entfernende Wert aus
mySet.
Rückgabewert
Rückgabewert ist true wenn value erfolgreich aus mySet entfernt wurde; ansonstenfalse.
Beispiel
Verwenden der delete() Methode
const mySet = new Set();
mySet.add('foo');
mySet.delete('bar'); // Returns false. No "bar" element found to be deleted.
mySet.delete('foo'); // Returns true. Successfully removed.
mySet.has('foo'); // Returns false. The "foo" element is no longer present.
Ein Beispiel, wie ein Objekt aus einem Set entfernt werden kann.
const setObj = new Set(); // Create a New Set.
setObj.add({x: 10, y: 20}); // Add object in the set.
setObj.add({x: 20, y: 30}); // Add object in the set.
// Delete any point with `x > 10`.
setObj.forEach(function(point){
if (point.x > 10){
setObj.delete(point)
}
})
Spezifikationen
| Specification |
|---|
| ECMAScript (ECMA-262) Die Definition von 'Set.prototype.delete' 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 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
delete | Chrome Vollständige Unterstützung 38 | Edge Vollständige Unterstützung 12 | Firefox Vollständige Unterstützung 13 | IE Vollständige 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
- Benutzer muss dieses Feature explizit aktivieren.
- Benutzer muss dieses Feature explizit aktivieren.