Reputation: 107
I am trying to delete an element from an object but it is not deleting from the object.
My Object is in the following format
{"UNDET":0,"HLDS":8,"NGS":2,"NGRT":1,"TotalCount":13,"NGX":1}
Now, I want to delete the key and value of an element(for ex: "NGRT":1) based on its index or key name, I have tried splicing elements individually i.e keys and values separately but the problem here is after splicing elements the keys and values are getting misaligned
Any help is appreciated.
Thanks in advance!
Upvotes: 1
Views: 822
Reputation: 38174
If you want to delete a key from an object, then use delete
operator:
const obj = {"UNDET":0,"HLDS":8,"NGS":2,"NGRT":1,"TotalCount":13,"NGX":1};
delete obj['NGRT'];
console.log(obj);
The JavaScript delete operator removes a property from an object; if no more references to the same property are held, it is eventually released automatically.
Upvotes: 2