I have an array with nested Objects with dynamic keys similar to this
const arr = [
{
"x1": [
{
"x1-point1": [
{
"value": 200,
"angle": 20
},
{
"value": 23,
"angle": 90
}
]
},
{
"x1-point2": [
{
"value": 54,
"angle": 0
}
]
},
{
"x1-point3": [
{
"value": 79
}
]
}
]
},
{
"x2": [
{
"x2-point1": [
{
"value": 12
}
]
},
{
"x2-point2": [
{
"value": 24
}
]
},
{
"x2-point3": [
{
"value": 36
}
]
}
]
}
]
Im trying to search the value and get the parent keys along with the resultant child What i tried was this
val = 200
arr.filter(r => !!Object.values(r).find(t => t.value == val))
My expected result would be
[
{
"x1": [
{
"x1-point1": [
{
"value": 200,
"angle": 20
}
]
}
]
}
]
What is that im doing wrong here, Im filtering the innermost child matching with the string and getting its parent keys