Currently, I am developing an Angular application where I am dealing with a specific array that contains a flag named "checked". Based on the value of this flag, I need to perform certain manipulations. Here is a snippet of my sample data:
const 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"
}
}
}
}
]
},
{
"checked": true,
"data": {
"name": "myName10"
},
"parent": {
"data": {
"name": "myName11"
},
"parent": {
"data": {
"name": "myName12"
}
}
}
},
{
"checked": false,
"data": {
"name": "myName13"
},
"parent": {
"data": {
"name": "myName14"
},
"parent": {
"data": {
"name": "myName15"
}
}
}
}
];
Within this array, if the "checked" flag is true for any index, I would like to check the "checked" flag for each child element. If the "checked" flag is true for any child, I want to extract the data from the parent's name to the child's name, separated by a "/". For the given data, the final array should look like this:
result = ["myName3/myName2/myName","myName3/myName2/myNamePart2","myName9/myName8/myName7","myName12/myName11/myName10"]
How can I achieve this?