I have the following collection. Each object may have a children
array of objects, which may have a children
array of objects and so on...
[
{
"name": "John",
"age": 24,
"children": [
{
"name": "Jack",
"age": 53,
"children": [
{
"name": "Jenny",
"age": 88
}
]
}
]
},
{
"name": "George",
"age": 45,
"children": [
{
"name": "Chris",
"age": 38,
"children": [
{
"name": "Nick",
"age": 35,
"children": [
{
"name": "Maria",
"age": 63
}
]
}
]
}
]
}
]
I want to recursively flatten the collection in order to have the following result:
[
{
"name": "John",
"age": 24
},
{
"name": "Jack",
"age": 53
},
{
"name": "Jenny",
"age": 88
},
{
"name": "George",
"age": 45
},
{
"name": "Chris",
"age": 38
},
{
"name": "Nick",
"age": 35
},
{
"name": "Maria",
"age": 63
}
]
How can i do this in lodash.js?
Try: