Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Set.prototype.delete

Removes a value from a Set.

Available since: ES2015

Syntax

set.delete(value)

Parameters

ParameterTypeDescription
valueanyThe 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
Oleg

Notes

The method changes the Set itself. To remove every value use clear().

See also

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.

Thanks for reading!

Donate to the site — we work hard for you.