How do I find an object from another object and delete it?

Question:
I have this object: {22152: {Cat: {x: 25, y:25}, Dog: {x: 25, y:25}}, 98267: {Bird: {x: 25, y:25}, Fish: {x: 25, y:25}}} and I’m looking to delete {Dog: {x: 25, y:25}} from it. How do I find the object and delete it?

@ColoredHue I’m like 75% sure this’ll work:

del PUT_OBJECT_NAME_HERE

Obviously, replace “PUT_OBJECT_NAME_HERE” with the name of your object.

The problem with this, is that I don’t know the object name ({Dog: {x: 25, y:25}}), i have to find it from the object: {22152: {Cat: {x: 25, y:25}, Dog: {x: 25, y:25}}, 98267: {Bird: {x: 25, y:25}, Fish: {x: 25, y:25}}}

I asked some friends and they helped me find a solution:

for(let key in lobbies) {
    if(lobbies[key].hasOwnProperty(socket.id)) {
        delete lobbies[key][socket.id];
    }
}
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.