How to delete a property of an object in JavaScript?

To delete a property of an object, delete key word should be used. Delete key word can be used with both the methods such as Dot method and Bracket method.

syntax

delete object.property;

Example

In the following example initially when the property "country" is executed its value "England" is displayed in the output. But when that property is deleted using delete keyword,instead of "England", undefined is displayed as shown in the output.

Live Demo

<html>
<body>
<script>
var txt = "";
var person = {
"name":"Ram",
"age":27,
"houseno" : 123,
"streetname" : "Baker street",
"country": "England"
}
}
document.write("Before deletion :" + " "+ person.address.country);
</html>
Before deletion : England
After deletion : undefined