I need to disable the active status for all elements within my object structure. Here is an example of my object:
const obj =
{ name: 'obj1'
, ative: true
, children:
[ { name: 'obj2'
, ative: true
, children:
[ { name: 'Obj23'
, ative: true
, children: [...]
} ] }
, { name: 'obj3'
, children:
[ { name: 'Obj32'
, ative: true
, children: [...]
} ] }
, ...
}
My goal is to set the active
property to false
for the main object obj1
and all its children, including sub-children.
I am unsure of how many levels of children there might be under each child, so I believe a loop using something like map
will be necessary.
The loop should terminate when a child has no further children (length equals 0).
UPDATE: I appreciate all the helpful solutions provided. Thank you!