• Post category:JavaScript
  • Reading time:1 mins read

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

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..!!

Leave a Reply