I'm looking to flatten an array that look like this:
[{
"id": 0,
"text": "item 0"
}, {
"id": 1,
"items": [{
"id": 2,
"text": "item 2"
}, {
"id": 3,
"items": [{
"id": 4,
"text": "item 4"
}]
}]
}]
into this
[{
"id": 0,
"text": "item 0"
}, {
"id": 2,
"text": "item 2"
}, {
"id": 4,
"text": "item 4"
}]
basically keeping all element that doesn't have an "items" property, and if they have one, recursively traverse all "items" arrays deep.
I could indeed write a recursive function, but I'm looking for a nice looking lodash or underscore way to solve this.