solvit.io

Remove a property from a JavaScript object

Solution
delete objectName.propertyName;

// this alternative syntax works too:
delete objectName['propertyName'];
Example
var myObject = { 'foo1': 'bar1', 'foo2': 'bar2', 'foo-3': 'bar3' };

delete myObject.foo1;
// myObject = { 'foo2': 'bar2', 'foo-3': 'bar3' };

delete myObject['foo-3'];
// myObject = { 'foo2': 'bar2' };
Find more solutions about: ,