Remove a JSON attribute [duplicate] Remove a JSON attribute [duplicate] json json

Remove a JSON attribute [duplicate]


delete myObj.test.key1;

The selected answer would work for as long as you know the key itself that you want to delete but if it should be truly dynamic you would need to use the [] notation instead of the dot notation.

For example:

var keyToDelete = "key1";var myObj = {"test": {"key1": "value", "key2": "value"}}//that will not work.delete myObj.test.keyToDelete 

instead you would need to use:

delete myObj.test[keyToDelete];

Substitute the dot notation with [] notation for those values that you want evaluated before being deleted.