How to remove a property from object in javascript?

In this article, We’ll see how to remove a property from a javascript object?




let’s create a employee object as follows:

const employee = {
  "name" : "John Doe",
  "age" : 35,
  "address" : "Los Angeles, USA"
}
console.log(employee); // Output {name: "John Doe", age: 35, address: "Los Angeles, USA"}

if we want to remove the property “address” from employee object. what will do ?

We’ll use delete keyword to remove the property from object.

    delete employee.address;
    // or,
    delete employee['address'];
    // or,
    var prop = "address";
    delete employee[prop];
    
    console.log(employee); // Output {name: "John Doe", age: 35}

That’s it!. Please share your thoughts or suggestions in the comments below.

Leave a Reply

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