JavaScript Set delete() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Instance method

Definition

set.delete(value) removes one value from a Set. It tells you what happened: it returns true if the value was in the Set and is now removed, and false if the value was not there.

It never throws an error for a missing value, so it is safe to call even when you are not sure the value exists. Use clear() when you want to remove everything.

Remember
set.delete(value)

value was in the Set   → removed, returns true
value was not there    → nothing changes, returns false

Objects must be the very same object
Never throws for a missing value

Syntax

Call it on a Set and pass the value to remove. Use the returned true or false if you need it.

JavaScript
const fruits = new Set(["apple", "banana", "cherry"]);

console.log(fruits.delete("banana"));   // true
console.log(fruits.delete("banana"));   // false (already gone)
console.log(fruits.size);               // 2
CallWhat it does
set.delete(value)Remove value. Returns true if it was removed.
if (set.delete(value)) { ... }Run code only when something was really removed.
set.clear()Remove every value, not just one.
set.has(value)Check first, without removing anything.

A standard JavaScript method (ES2015) on every Set, from Set.prototype. No import required. Siblings: add(), clear(), difference(), entries(), forEach(), has(), intersection(), isDisjointFrom(), isSubsetOf(), isSupersetOf(), keys(), symmetricDifference(), union(), values(), [Symbol.iterator]().

Library declarations
JavaScript
// ECMAScript 2015 (ES6)
Set.prototype.delete(value)

// value  : the value to remove
// returns: true if it was removed, false if it was not in the Set

Parameters

ParameterDescription
valueRequired. The value to remove. It is compared like in add() and has(): NaN matches NaN, and objects match only when they are the very same object.

Return Value

Return ValueDescription
trueThe value was in the Set, and it has been removed.
falseThe value was not in the Set, so nothing changed.

JavaScript Examples

Example 1 — Remove a Value and Read the Result

Delete a value that exists, delete it again, delete one that never existed, and look at what is left.

JavaScript
const fruits = new Set(["apple", "banana", "cherry"]);

console.log("Delete banana: " + fruits.delete("banana"));
console.log("Delete banana again: " + fruits.delete("banana"));
console.log("Delete grape: " + fruits.delete("grape"));
console.log("Left: " + Array.from(fruits).join(", "));
Try It Yourself

How It Works

  1. First delete. "banana" is in the Set, so it is removed and the call returns true.
  2. Second delete. Now "banana" is gone, so the same call returns false. "grape" was never added, so it returns false too. No error is thrown.
  3. What is left. Only apple and cherry remain, in their original order.

Example 2 — Delete an Object from a Set

A Set finds objects by identity. Try to delete a look-alike copy, and then the real object.

JavaScript
const ann = { name: "Ann" };
const people = new Set([ann, { name: "Bob" }]);

console.log("Delete a copy: " + people.delete({ name: "Ann" }));
console.log("Delete the real object: " + people.delete(ann));
console.log("Size: " + people.size);
Try It Yourself

How It Works

  1. Keep a reference. ann is stored in a variable, and the same object is put into the Set. The second object has no variable.
  2. A copy does not match. { name: "Ann" } looks the same but is a different object, so delete() returns false and removes nothing.
  3. The real object matches. people.delete(ann) returns true. Only the Bob object is left, so the size is 1.

Example 3 — Delete Values While Looping

Loop over a Set of numbers and delete the even ones. Deleting inside a for...of loop is safe for a Set.

JavaScript
const numbers = new Set([1, 2, 3, 4, 5, 6]);

for (const n of numbers) {
  if (n % 2 === 0) {
    numbers.delete(n);
  }
}

console.log("Odd numbers: " + Array.from(numbers).join(", "));
console.log("Size: " + numbers.size);
Try It Yourself

How It Works

  1. Walk through the Set. for...of visits 1 to 6 in the order they were added.
  2. Delete the even ones. n % 2 === 0 is true for 2, 4 and 6, so each of them is removed with delete(n) while the loop is running.
  3. The loop is not confused. Removing the value that is being visited does not skip or repeat any other value. The Set ends with 1, 3, 5.

Browser & Runtime Support

Set.prototype.delete() is part of ES2015 (ES6), together with Set itself. Every current browser and Node.js has it.

✓ ES2015 · Widely supported

set.delete()

Supported in Chrome 38+, Edge 12+, Firefox 37+, Safari 9+, Opera 25+ and Node.js 4+. Internet Explorer 11 only has a basic Set.

ES2015 Standard since
Google Chrome 38+ · Desktop & Mobile
Full support
Microsoft Edge 12+ · Chromium based
Full support
Mozilla Firefox 37+ · Desktop & Mobile
Full support
Apple Safari 9+ · macOS & iOS
Full support
Opera 25+ · Chromium based
Full support
Samsung Internet Recent versions · Android
Supported
Android WebView 38+ · Chromium based
Supported
Node.js 4+ · Server runtime
Supported
Deno Recent versions · JavaScript runtime
Supported
Bun Recent versions · JavaScript runtime
Supported
Internet Explorer IE 11 · basic Set only
Partial support
set.delete() Excellent

Bottom line: Safe to use in every current browser and in Node.js. Only Internet Explorer needs special care.

Frequently Asked Questions

It returns true if the value was in the Set and has been removed, and false if the value was not there. It never throws an error because of a missing value.
Pass the very same object that is stored in the Set. A Set compares objects by identity, so a copy with the same properties is a different value and is not removed. Keep the object in a variable, or find it with a loop, before you delete it.
Yes. Deleting inside for...of or forEach() is safe. A value that you delete before the loop reaches it is skipped, and the other values are still visited once.
delete(value) removes one value and tells you with true or false. clear() removes every value and returns undefined. Use delete() for one item and clear() to start again from an empty Set.
No. delete() already returns false when the value is missing. Check has() only if you want to do something different before removing, because has() followed by delete() looks the value up twice.

Next: difference()

Learn how to get the values that are in one Set but not in another, without changing either Set.

difference() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful