标签云

微信群

扫码加入我们

WeChat QR Code

如何删除嵌套的对象属性[复制]

This question already has an answer here:

I have a object like this.

var Obj = {
    obj1 : {
        val : 1,
        id : 1
    }
    obj2 : {
        val : 2,
        id :2
    }
    obj3 : {
        val : 3,
        id :3
    }
}

I want to delete obj1, can anybody suggest how to achieve this.


This is invalid object!

2018年05月27日23分00秒

DhavalMarthak If I make obj=1 then is it valid ?

2018年05月28日23分00秒

CarlosRivero But in my case it is attributes are dynamic, I can not randomly delete any specific attribute

2018年05月27日23分00秒

Surely you just use the dot notation and set it to undefined? Obj.obj1 = undefined?

2018年05月27日23分00秒

thanks, or any way by I can retrieve as a loop

2018年05月27日23分00秒