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.