existing data:
var res = [{
code: 1,
name: "",
children: [{
code: 1,
name: "",
children: [{
code: 1,
name: "",
children: [{
code: 1,
name: ""
}]
}, {
code: 1,
name: "",
children: [{
code: 1,
name: ""
}]
}, {
code: 1,
name: "",
children: [{
code: 1,
name: ""
}]
}]
}, {
code: 1,
name: "",
children: [{
code: 1,
name: "",
children: [{
code: 1,
name: ""
}]
}, {
code: 1,
name: "",
children: [{
code: 1,
name: ""
}]
}]
}]
}]
want to recursively get the data in the following format (that is, some fields that Filter does not need):
var newData = [{
name: "",
children: [{
name: "",
children: [{
name: "",
children: [{
name: ""
}]
...
}]
},{
name: "",
children: [{
name: "",
children: [{
name: ""
}]
...
}]
}]
}]
now I can only use nested loops to solve the problem. If you want to simplify the code or don"t know how many layers there are, nested loops certainly won"t work. How can I implement them with recursion?