Set

Set.prototype.delete

Removes the specified element from a Set object

Syntax

JavaScript
set.delete(value)

Parameters

ParameterTypeDescription
valueTThe value to remove

Return Value

true if the value was in the set and has been removed, false otherwise

Examples

Basic Usage
const set = new Set([1, 2, 3]);
console.log(set.delete(2)); // true
console.log(set.delete(4)); // false
console.log(set.size); // 2
Practical Example
const online = new Set<string>();
online.add('alice');
online.add('bob');
online.delete('alice');
console.log([...online]); // ['bob']
Advanced Usage
const set = new Set(['a', 'b', 'c', 'd']);
for (const val of set) {
  if (val > 'b') set.delete(val);
}
console.log([...set]); // ['a', 'b']

Understanding Set.prototype.delete

The Set.prototype.delete method in JavaScript removes the specified element from a Set object. It belongs to the Set object and is one of the most widely used methods for working with set values in modern JavaScript and TypeScript applications.

The method signature is set.delete(value). It accepts 1 parameter: value. When called, it returns true if the value was in the set and has been removed, false otherwise. Understanding when and how to use delete() helps you write more expressive, readable code.

Common use cases for Set.prototype.delete include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like set-add, set-has, set-clear, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Set.prototype.delete is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Set Methods

Other methods in the Set object

Related Tools

More Set Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.