Storing data in an array on the basis of a flag

I am working on a angular application. I have one array and in it I have one flag "checked". I need to do some manipulation
on the basis of this flag. My sample data is as follows:

data = [{
"checked": true,
"children": [{
 "checked": true,
 "data":{
   "name": "myName"
 },
 "parent": {
   "data": {
      "name": "myName2"
   },
   "parent":{
     "data": {
      "name": "myName3"
   }
    }
 }
},
{
 "checked": true,
 "data":{
   "name": "myNamePart2"
 },
 "parent": {
   "data": {
      "name": "myName2"
   },
   "parent":{
     "data": {
      "name": "myName3"
   }
    }
 }
}
]
},{
"checked": false,
"children": [{
 "checked": true,
 "data":{
   "name": "myName4"
 },
 "parent": {
   "data": {
      "name": "myName5"
   },
   "parent":{
     "data": {
      "name": "myName6"
   }
    }
 }
}]
},{

"checked": true,
"children": [{
 "checked": true,
 "data":{
   "name": "myName7"
 },
 "parent": {
   "data": {
      "name": "myName8"
   },
   "parent":{
     "data": {
      "name": "myName9"
   }
    }
 }
}]
}]

In this array, if for any index if "checked" is true, then I want to check the "checked" flag for each children. If for any children, if "checked" flag is
true, then I want to have data from parent name to children name separated by "/" in an array. For above data my final array will have

result = ["myName3/myName2/myName","myName3/myName2/myNamePart2","myName9/myName8/myName7"]

How can I do that?

Source: Ask Javascript Questions

LEAVE A COMMENT