
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
<html> <body> <script> var txt = ""; var person = { "name":"Ram", "age":27, "address": { "houseno" : 123, "streetname" : "Baker street", "country": "England" } } document.write("Before deletion :" + " "+ person.address.country); delete person.address.country; document.write("</br>"); document.write("After deletion :" + " "+ person.address.country); </script> </body> </html>
Output
Before deletion : England After deletion : undefined
Advertisements