how to match two tree arrays and return the corresponding values, such as
const arr = [
{
id: 1,
name: "a",
icon: "b",
children: [
{
id: 1-1,
name: "a-1",
icon: "b-1",
children: [
{
id: 1-1-1,
name: "a-1-1",
icon: "b-1-1",
},
{
id: 1-1-2,
name: "a-1-2",
icon: "b-1-2",
}
]
},
{
id: 1-2,
name: "a-2",
icon: "b-2",
}
]
},
{
id: 2,
name: "c",
icon: "d",
children: [
{
id: 2-1,
name: "c-1",
icon: "d-1",
children: [
{
id: 2-1-1,
name: "c-1-1",
icon: "d-1-1",
}
]
}
]
},
{
id: 3,
name: "e",
icon: "f",
}
]
const arr2 = [
{
id: 1,
children: [
{
id: 1-1,
children: [
{
id: 1-1-1
}
]
}
]
},
{
id: 2,
children: [
{
id: 2-1
}
]
}
]
return:
[
{
id: 1,
name: "a",
icon: "b",
children: [
{
id: 1-1,
name: "a-1",
icon: "b-1",
children: [
{
id: 1-1-1,
name: "a-1-1",
icon: "b-1-1"
}
]
}
]
},
{
id: 2,
name: "c",
icon: "d",
children: [
{
id: 2-1,
name: "c-1",
icon: "d-1"
}
]
},