I am working on a vue js app and i have the following recursive array :
[
{
id: 1,
name: "sam",
list: [
{
id: 2,
name: "john",
list: []
},
{
id: 6,
name: "sarah",
list: [
{
id: 21,
name: "fadi",
list: []
}
]
}
]
},
{
id: 3,
name: "ross",
list: [
{
id: 4,
name: "maya",
list: []
}
]
},
{
id: 5,
name: "steph",
list: []
},
{
id: 7,
name: "joseph",
list: []
},
],
So i have the id of the object that needs moving and the id of where it should be moved for example i get idmoving=6 and destination = 2 so the object of id 6 with its content should move to the list of the object of id 2 the list becomes the following:
[
{
id: 1,
name: "sam",
list: [
{
id: 2,
name: "john",
list: [
{
id: 6,
name: "sarah",
list: [
{
id: 21,
name: "fadi",
list: []
}
]
}
]
},
]
},
{
id: 3,
name: "ross",
list: [
{
id: 4,
name: "maya",
list: []
}
]
},
{
id: 5,
name: "steph",
list: []
},
{
id: 7,
name: "joseph",
list: []
},
],
I'm sorry i'm still new to this i hope someone can help with a function that can do that.