I use an API that returns results in a format that includes additional nodes. I want to execute the results recursively in order to remove the “data” nodes so that I can use them in my application.
Can I do this with simple javascript or Lodash?
These are the results that I get:
"pages": {
"data": [
{
"id": 32,
"pages": {
"data": [
{
"id": 33,
"pages": {
"data": []
}
},
{
"id": 34,
"pages": {
"data": [
{
"id": 35,
"pages": {
"data": []
}
}
]
}
}
]
}
},
{
"id": 36,
"pages": {
"data": []
}
}
]
This is what I would like to return:
"pages": [
{
"id": 32,
"pages": [
{
"id": 33,
"pages": []
},
{
"id": 34,
"pages": [
{
"id": 35,
"pages": []
}
]
}
]
},
{
"id": 36,
"pages": []
}
]
source
share