I have an object like this:
var names = { 45: "Jeff", 145: "Peter", 11: "Dandie", 879: "Michael" }
How do I remove "Peter" from the object?
I have an object like this:
var names = { 45: "Jeff", 145: "Peter", 11: "Dandie", 879: "Michael" }
How do I remove "Peter" from the object?
The code is bad practice, the keys and values are in the wrong order. Try the following to achieve what you want:
for(var key of Object.keys(names))
if(names[key]=='John')
delete names[key];
Without for .. of:
Object.keys(names).forEach(function(key){
if(names[key]=='John')
delete names[keys];
});