Set.prototype.delete
Removes a value from a Set.
Available since: ES2015
Syntax
set.delete(value)Parameters
| Parameter | Type | Description |
|---|---|---|
| value | any | The value to remove. |
Return value
booleantrue if the value existed and was removed.
Examples
Removing and trying again:
const online = new Set(['Anna', 'Oleg']);
console.log(online.delete('Anna'));
console.log(online.delete('Anna'));
console.log([...online].join(', '));Output:
true
false
OlegNotes
The method changes the Set itself. To remove every value use clear().
See also
- Set.prototype.add — Adds a value to a Set if it is not there yet.
- Set.prototype.clear — Removes all values from a Set.
In the tutorial
- Map and Set — The Map and Set collections in JavaScript: a dictionary with keys of any type and a set of unique values.