Clue Mediator

Remove a property from an object in JavaScript

πŸ“…November 23, 2021
πŸ—JavaScript

Today we will show you how to remove a property from an object in JavaScript. We will see several methods with examples.

Checkout more articles on JavaScript

Remove a property from an object (mutating the object)

You can do it like this:

delete myObject.foo;
// or
delete myObject['foo'];
// or,
var prop = "foo";
delete myObject[prop];

Example:

var myObject = {
    "foo": "123",
    "bar": "456",
    "baz": "789"
};
delete myObject.foo;

console.log(myObject);
// Output: { "bar": "456", "baz": "789" }

I hope you find this article helpful.
Thank you for reading. Happy Coding..!! πŸ™‚