A recursive word cannot be written in the work. Ask the master for help and accept a reward. Thank you. Thanks Thanks ()
has the following data
[{
id: "1",
name: "1",
items: [
{
id: "2",
name: "2",
items: [
{
id: "3",
name: "3",
items: [
{
id: "4",
name: "4",
},
],
},
],
},
{
id: "5",
name: "5",
},
{
id: "6",
name: "6",
},
],
},
{
id: "7",
name: "7",
}];
requires that there be a function, pass in an id value, and find out from the data the object whose id is passed in id, and all the parent objects of this object
for example, if the input id is" 5percent, then
is returned.[{id: "5", name: "5"}, {id: "1", name: "1"}]
input id is" 3percent, return
[{id: "3", name: "3"}, {id: "2", name: "2"}, {id: "1", name: "1"}]
Thank you for your help ~