1

I need help with removing a property from a Javascript object. It looks like this:

devices = {
    device1 : {
        properties : {
            name : {
                value : "ABC"
            },
            id: {
                value : "1234"
            }
        }
    },
    device2 : {
        properties : {
            id: {
                value : "5678"
            }
        }
    }
};

I now get a path for the property to delete:

var path_str = "device1___properties___name___value";

I split it to an array:

var path = path_str.split("__");

When the parent (or parent's parent... to top) is containing only the single element, it should be removed too.

So deleting "device1___properties___name___value" would keep "device1___properties___*",

but deleting "device2___properties___id___value" would remove "device2" property completely, keeping only other "device*" properties.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Dommar92
  • 325
  • 1
  • 2
  • 13

0 Answers0