such a multi-layer array,
let json = [
{
id: "1",
name: "1",
children: [
{
id: "1-1",
name: "1-1",
children: [
{
id: "1-1-1",
name: "1-1-1"
},
{
id: "1-1-2",
name: "1-1-2"
}
]
},
{
id: "1-2",
name: "1-2"
}
]
},
{
id: "2-1",
name: "2-1"
},
{
id: "3-1",
name: "3-1",
children: [
{
id: "3-1-1",
name: "3-1-1"
}
]
}
]
for example, the function is searchParentElementArrays;
when I pass in searchParentElementArrays (json, id), print:
[["1", "1-1", "1-1-1"],["1", "1-1", "1-1-2"],["1", "1-2"],["2-1"],["3-1","3-1-1"]]
the environmental background of the problems and what methods you have tried
related codes
/ / Please paste the code text below (do not replace the code with pictures)