Set.prototype.delete()

Removes a value from a Set.

Since ES2015 (ES6) Spec ↗

Syntax

set.delete(value)

Returns

boolean — `true` if the value was present and removed, otherwise `false`.

Examples

const s = new Set([1, 2, 3]);
console.log(s.delete(2));
console.log([...s]);
Output
true
[ 1, 3 ]
const s = new Set();
console.log(s.delete(99));
Output
false

Notes

- Returns whether anything was actually removed. - Use `set.clear()` to remove all values at once.

Browser & runtime support

EnvironmentSince version
chrome 38
firefox 13
safari 8
edge 12
node 0.12

See also