I have a structure like this:
const tree = [
{
"a": "1",
"children": [
{
"a": "11",
"children": [
{ "a": "111", "p": "me" },
{ "a": "112" }
]
},
{ "a": "111", "p": "me" }
]
},
{ "a": "2" },
{ "text": "3", "p": "me" }
]
And I'm trying to filter the tree by p: "me"
, however, I keep bumping into the parent and can't get past it.
My desired output is something in these lines:
const res = filter(tree, "p", "me")
console.log(res)
/*
[
{
"a": "1",
"children": [
{
"a": "11",
"children": [
{ "a": "111", "p": "me" },
]
},
{ "a": "111", "p": "me" }
]
},
{ "text": "3", "p": "me" }
]
*/
I've tried other solutions and tweak them (like this one), but I'm struggling