-3

I'm trying to remove an object which is nested in another object by using the sub-object key.

Example:

var myMainObj = {
     'subObjA' = {
         'randomstuff' : 1,
         'randomstuff2' : 2,
      },
     'subObjB' = {
         'randomstuff' : 1,
         'randomstuff2' : 2,
     }

}

Now how would I go about completely remove the object "subObjB" if I know the keyname of it?

user3708279
  • 23
  • 1
  • 6

2 Answers2

2

You can use delete operartor:

delete myMainObj['subObjB'];

or

delete myMainObj.subObjB;
antyrat
  • 27,479
  • 9
  • 75
  • 76
0

you need to use delete operator:

delete myMainObj.subObjB;
Zaheer Ahmed
  • 28,160
  • 11
  • 74
  • 110