JavascriptJavaScript — delete a property from an object

JavaScript — delete a property from an object

You can remove a property from a JavaScript object with the delete operator.

And it’s super easy:

delete object.property

Example

var Car = {
    make: "Mazda",
    model: "CX-5",
    year: "2014"
};

console.log(Car.year);
// expected output: "2014"

delete Car.year;

console.log(Car.year);
// expected output: undefined

 

For more information:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete

Categories: Javascript Tags: , ,

Comments

No Comments Yet. Be the first?

Post a comment

Your email address will not be published. Required fields are marked *