JavaScript(JS) JS remove a property from an object

http‮‬s://www.theitroad.com

To remove a property from an object in JavaScript, you can use the delete keyword followed by the name of the property you want to remove. Here's an example:

let obj = {
  name: "John",
  age: 30,
  city: "New York"
};

delete obj.city;

console.log(obj); // Output: { name: "John", age: 30 }

In this code, we define an object obj with three properties: name, age, and city. We use the delete keyword to remove the city property from the object. Finally, we print the modified object to the console using console.log().

Note that if you try to delete a property that doesn't exist in the object, nothing will happen and the object will remain unchanged.