The JavaScript delete operator
The delete operator removes a property from an object. delete user.email removes the email property entirely. It returns true on success. It's for object properties only — it can't delete variables, and using it on an array leaves an empty hole rather than shifting elements.
Overview
delete removes a property from an object completely — not just setting it to undefined, but taking the key out so "email" in user becomes false afterward. delete obj.prop (or delete obj["prop"] for dynamic keys) is the operation. It returns true when it succeeds, which is almost always.
It has clear limits. It only works on object properties — you can't delete a variable, a function, or anything declared with let/const/var (those just stay). And on an array it's a trap: delete arr[1] removes the element but leaves an empty slot, so the length is unchanged and you get a sparse array with a hole. To actually remove an array element, use splice() (mutating) or filter() (new array).
For removing object properties, delete is fine, but in code that favors immutability you'll often build a new object without the key instead — destructuring the rest: const { email, ...without } = user. That leaves the original untouched, which suits React state and similar. There's also a minor performance note: deleting can deoptimize an object's internal shape, so in hot paths setting the value to undefined or using a Map may be preferable.
Syntax
delete object.property
delete object["property"]
const user = { name: "Ada", email: "a@x.com" };
delete user.email; // user is now { name: "Ada" }
delete arr[1]; // leaves a hole - use splice() instead
Example
<pre id="out" style="font:15px ui-monospace,monospace"></pre>
<script>
const user = { name: 'Ada', email: 'a@x.com', temp: true };
delete user.temp;
document.getElementById('out').textContent =
JSON.stringify(user) + '\n' +
"'temp' in user: " + ('temp' in user);
// {"name":"Ada","email":"a@x.com"} / 'temp' in user: false
</script>
Best practices
- Use
deleteto remove a property from an object. - Don't use it on arrays — it leaves an empty slot. Use splice() or filter() instead.
- For immutable code, build a new object without the key via rest destructuring.
- It can't delete variables or declarations — only object properties.
Frequently asked questions
How do I remove a property from an object?
delete obj.property (or delete obj["property"] for dynamic keys). It removes the key entirely.Why shouldn't I use delete on an array?
What is the difference between delete and setting a property to undefined?
delete removes the key, so "key" in obj becomes false; setting it to undefined keeps the key with an undefined value.How do I remove a property without mutating the object?
const { remove, ...rest } = obj gives a new object without that key.