JavaScript example

How to remove a property from an object in JavaScript

5 min read Updated Sep 2026 Runs in an isolated runtime
Quick answer

Use the delete operator: delete obj.key, or delete obj[name] when the key is in a variable. It changes the object in place. To get a copy without the key and leave the original alone, use rest destructuring: const { key, ...rest } = obj.

Those two cover almost every case, and the choice between them is really a choice about mutation. delete edits the object that every other reference also points at; destructuring builds a new object and touches nothing. The rest of the page covers dropping several keys at once, why obj.key = undefined is not a removal, and the few places delete quietly does nothing. Each example runs on this page: hit Run, then edit the code and run it again.

1The delete operatorRecommended

delete removes the property itself, key and value together, from the object you give it. Use dot notation for a fixed name and bracket notation when the name is in a variable or isn't a valid identifier (delete headers["x-api-key"]). After the delete, Object.hasOwn reports the key as gone.

delete.js

Output

Output: { name: 'Ada', role: 'admin' }, false, { name: 'Ada' }, then true. That last line matters: unlike Python's del, deleting a missing key is not an error, and the true it returns only means "the key is not there now", not "I removed something". If you need to know, check Object.hasOwn(obj, key) first.

2Rest destructuring: a copy without the key

When the object came from somewhere else (a function argument, React state, a shared config), mutating it can surprise the caller. Object rest destructuring pulls the unwanted key out into its own variable and collects everything else into a brand-new object. The original is never touched. For a key held in a variable, use a computed name and bind the value to a throwaway variable.

rest.js

Output

Prints { id: 7, name: 'Ada', role: 'admin' }, then hunter2, then the original user with password still in it, and finally { id: 7, name: 'Ada' }. The copy is shallow: nested objects are shared between user and publicUser, so editing a nested value through one shows up in the other.

3Removing several keys at once

Destructuring gets clumsy past two or three keys, and it can't take a list you only know at runtime. For that, turn the object into entries, filter them and turn them back with Object.fromEntries. That builds a new object. To edit the original instead, loop over the keys and delete each one; missing keys cost nothing. The same filter also handles the other common request, dropping every property whose value is null or undefined.

several-keys.js

Output

Both approaches print { id: 7, name: 'Ada', role: 'admin' }, and the last line prints { name: 'Ada', city: 'London' }. value != null is the one place loose equality is idiomatic: it is true for everything except null and undefined, so 0, "" and false survive. Object.entries only sees own, enumerable, string-keyed properties, so the copy drops symbol keys and the prototype.

4Setting a key to undefined is not removing it

obj.key = undefined looks like a removal because reading the key afterwards gives undefined either way. But the key is still on the object: in, Object.keys, for...in and spreading into another object all still see it. Only delete (or building a copy without it) makes the key disappear.

undefined.js

Output

Prints { name: 'Ada', email: undefined } { name: 'Ada' }, then true false, then [ 'name', 'email' ] [ 'name' ]. Reading the value can't tell them apart (true), and neither can JSON: both serialize to {"name":"Ada"}. So if the object is only ever sent as JSON, setting undefined works in practice, but anything that walks the keys will still find it.

5Which should you use?

MethodChanges the originalKey in a variableBest for
delete obj.keyYesdelete obj[k]Objects you own, removing in place
const { key, ...rest } = objNo, new object{ [k]: _, ...rest }One or two keys, immutable updates
Object.fromEntries(entries.filter(…))No, new objectAny list of keysMany keys, or dropping by value
obj.key = undefinedYesobj[k] = undefinedNot a removal: the key stays
map.delete(key)YesAny key typeMaps: returns whether it removed

6When delete does nothing: frozen objects, prototypes and Maps

A few cases trip people up. A Map is not a plain object, so delete doesn't apply; it has its own .delete(key) method, which, unlike the operator, tells you whether it actually removed something. A frozen (or sealed) object refuses deletes: a plain script fails silently, while strict code throws a TypeError. And delete only removes an object's own property, so a property with the same name on the prototype shows through afterwards.

edge-cases.js

Output

ports.delete prints true false and leaves Map(1) { 'http' => 80 }. The frozen object returns false in the plain script and throws TypeError: Cannot delete property 'debug' of #<Object> inside the strict function; either way config is unchanged. The last line prints hello false: the own greeting is gone, and the inherited one answers instead. Code in ES modules and class bodies is always strict, so there a failed delete always throws.

Frequently asked questions

How do I remove a property from an object without mutating it?

Use object rest destructuring: const { password, ...rest } = user gives you rest, a new object with every property except password, and leaves user unchanged. For a key held in a variable, write const { [key]: _, ...rest } = obj. For several keys, filter the entries: Object.fromEntries(Object.entries(obj).filter(([k]) => !drop.has(k))).

What does delete return in JavaScript?

It returns true when the property is gone afterwards, which includes the case where it was never there, so delete obj.missing is also true. It returns false only when the property exists and cannot be removed, such as on a frozen object in non-strict code; in strict code that case throws a TypeError instead. Reflect.deleteProperty(obj, key) gives the same boolean without ever throwing.

Is setting a property to undefined the same as deleting it?

No. After obj.key = undefined the key still exists: "key" in obj is true and Object.keys(obj) still lists it. After delete obj.key both say it is gone. They only look the same when you read the value or serialize with JSON.stringify, which skips undefined values.

Should I use delete on arrays?

No. delete arr[1] removes the value but not the slot, leaving a hole and the same length. To remove an array item, use arr.toSpliced(index, 1) or arr.filter(...) for a new array, or arr.splice(index, 1) to change it in place.

Is delete slow in JavaScript?

It can be in hot code. Engines like V8 optimize objects by their shape, and deleting a property can switch an object to a slower dictionary mode. For an object you build once and trim, it does not matter. For objects used as frequently changing lookup tables, use a Map and map.delete(key), which is designed for adding and removing keys.

Run it yourself

Open any of these in the full JavaScript editor: tweak, run, and share.

JavaScript playground