Home » Articles posted by MathaPachi

Author Archives: MathaPachi

How to delete a Property From a Javascript Object ?

In Javascript, a property can be removed from object. Let’s take an example to delete a property from javascript object.

var employeeObj = {
    "name": "Deepak",
    "rollno": "37673",
    "email": "abc@gmail.com"
};

To delete a property e.g. name in the above object, the below statement needs to be put in.

delete employeeObj.name;

The same can be written in different forms as well. e.g.

delete employeeObj[‘name’];

var prop = “name”;
delete employeeObj[prop];

To get the output after deleting , execute the below statement:
console.log(employeeObj);

O/p : 
var employeeObj = {
    "rollno": "37673",
    "email": "abc@gmail.com"
};