Trying to filter data from a 3-layer array based on child array values. Making progress but hitting a roadblock at the end.
{
"id": 1,
"grandparent": "Timmy",
"parents": [
{
"id": 1,
"parent": "Johnny",
"children": [
{
"id": 1,
"child": "Sam",
"checked": true
},
{
"id": 1,
"child": "Ted",
"checked": false
}
]
},
{
"id": 2,
"parent": "Jessica",
"children": [
{
"id": 1,
"child": "Sam",
"checked": false
}
]
},
]
}
Current code snippet:
grandparents.value = value.value.map((el) => ({
...el,
parents: el.components.filter((parent) => parent.children?.some((child) => child.checked))
}))
Current output:
{
"id": 1,
"grandparent": "Timmy",
"parents": [
{
"id": 1,
"parent": "Johnny",
"children": [
{
"id": 1,
"child": "Sam",
"checked": true
},
{
"id": 1,
"child": "Ted",
"checked": false
}
]
}
]
}
Successful filtering of the parents array, now aiming to also filter out unchecked children.
Desired results
{
"id": 1,
"grandparent": "Timmy",
"parents": [
{
"id": 1,
"parent": "Johnny",
"children": [
{
"id": 1,
"child": "Sam",
"checked": true
}
]
}
]