Skip to main content

How to remove property / key from an object in nodejs

In Node.js, you can remove a property or key from an object using the `delete` keyword.

Here's an example:

const myObj = {
  name: 'John',
  age: 30,
  city: 'New York'
};

delete myObj.city;

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

In this example, we create an object `myObj` with three properties: `name`, `age`, and `city`. We then use the `delete` keyword to remove the `city` property from the object. Finally, we log the object to the console to verify that the `city` property has been removed.