I'm having troubles deleting properties with no keys in its value.
obj = {person: {id: 1, name: 'isaac'},
location: {id: 1, name: 'UT'},
status: {id: 1, name: 'Active'},
empty: {}
}
for (key in obj) {
if (Object.keys(obj.key).length == 0) {
delete obj.key
}
}
Running this code in chrome console I get the error:
Uncaught TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at <anonymous>:2:16
(anonymous) @ VM13940:2
I know this comes from Object.keys receiving null or undefined.
I don't understand how unless there is something going on with the object Prototype that I'm not seeing.