How to remove a property from a Javascript Object

You would like to remove a given property from a javascript object. Here is a simple example of how you could do it :

You have defined an object similar to the following:

let oneObject = { “Prop1”: “Val1”, “Prop2”: “Val2” };

And you would like to remove one property, say “Prop1”, from the object oneObject so that it becomes defined as follows :

oneObject = { “Prop2”: “Val2” };

Read: How to remove duplicates from Arrays in Javascript

In order to do this, simply write the following code :

delete oneObject.Prop1;

Read: How to check if a string contains another string in JavaScript

Or, if you like write also:

delete oneObject[‘Prop1’];

 

Read: Should You Learn JavaScript, Advice for Newbie Web Developers


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

Marianne elanotta

Marianne is a graduate in communication technologies and enjoys sharing the latest technological advances across various fields. Her programming skills include Java OO and Javascript, and she prefers working on open-source operating systems. In her free time, she enjoys playing chess and computer games with her two children.

Leave a Reply