Asked 1 years ago
24 Apr 2023
Views 237
ajamil

ajamil posted

How do I remove a property or element from a JavaScript object?

you have a JavaScript object, let's say:


let myObj = { 
  name: 'John', 
  age: 25, 
  city: 'New York' 
};

Now, want to remove a property or element from this object. What is the process to achieve this in JavaScript?
Phpworker

Phpworker
answered Jun 29 '23 00:00

you can remove a property or element from an object using the delete keyword
david

david
answered Jun 29 '23 00:00


let myObj = { 
  name: 'John', 
  age: 25, 
  city: 'New York' 
};

delete myObj.age;

console.log(myObj);

delete myObj.age; will remove a 'age' element from myObj object
Post Answer