Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Set.prototype.delete — removing a value from a set

Set.prototype.delete(value) removes the specified value from an existing set. It returns true if removal occurred, or false if the value was absent. Objects are matched by identity rather than by their contents.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

set.delete(value)

set.delete(value) mutates an existing Set: it removes the matching value and returns true. If the value is absent, it returns false without changing the set. The argument specifies a value, not an index. The result is a boolean, not the set, so consecutive .delete() calls cannot be chained.

Matching follows SameValueZero semantics: NaN matches NaN, and +0 and -0 are treated as the same value. Objects are compared by identity. A new object { id: 1 } does not match a previously added object with the same fields; you must pass a reference to the same object.

Do not confuse this method with the delete operator, which removes object properties, or with set.clear(), which removes all elements. The method requires a receiver with internal Set data; calling Set.prototype.delete.call({}, value) throws TypeError. This is an ECMAScript language API, not a browser API; the presence of Node.js in a project alone does not confirm support in target browsers.

Examples

const item = { id: 1 };
const values = new Set(["ready", item, NaN]);

console.log(values.delete("ready"));
console.log(values.delete("ready"));
console.log(values.delete({ id: 1 }));
console.log(values.delete(item));
console.log(values.delete(NaN));
console.log(values.size);

Result

true
false
false
true
true
0

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources