| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since July 2015.
The delete() method of Set instances removes the specified value from this set, if it is in the set.
const set = new Set();
set.add({ x: 10, y: 20 }).add({ x: 20, y: 30 });
// Delete any point with `x > 10`.
set.forEach((point) => {
if (point.x > 10) {
set.delete(point);
}
});
console.log(set.size);
// Expected output: 1
setInstance.delete(value)
true if a value in the Set object has been removed successfully. false if the value is not found in the Set.
const mySet = new Set();
mySet.add("foo");
console.log(mySet.delete("bar")); // false; no "bar" element found to be deleted.
console.log(mySet.delete("foo")); // true; successfully removed.
console.log(mySet.has("foo")); // false; the "foo" element is no longer present.
Because objects are compared by reference, you have to delete them by checking individual properties if you don't have a reference to the original object.
const setObj = new Set(); // Create a new set.
setObj.add({ x: 10, y: 20 }); // Add object in the set.
setObj.add({ x: 20, y: 30 }); // Add object in the set.
// Delete any point with `x > 10`.
setObj.forEach((point) => {
if (point.x > 10) {
setObj.delete(point);
}
});
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-set.prototype.delete |
This page was last modified on Sep 22, 2025 by MDN contributors.
SetObject/FunctionYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |