Remove a property from an object in 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:
1 2 3 4 5 6 | delete myObject.foo; // or delete myObject['foo']; // or, var prop = "foo"; delete myObject[prop]; |
Example:
1 2 3 4 5 6 7 8 9 | 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..!! 🙂