Seeking a solution to transform this array of nested objects into a flat array for easier manipulation.
[
{
"name": "bill",
"car": "jaguar",
"age": 30,
"profiles": [
{
"name": "stacey",
"car": "lambo",
"age": 23,
"profiles": [
{
"name": "martin",
"car": "lexus",
"age": 34,
"profiles": []
}
]
}
]
}
]
The desired result is shown below:
[
{
"name": "bill",
"car": "jaguar",
"age": 30,
},{
"name": "stacey",
"car": "lambo",
"age": 23,
},{
"name": "martin",
"car": "lexus",
"age": 34,
}
]
Each profiles
array can have any number of items, some possibly with empty subarrays of profiles. The converted objects in the array do not include the profiles after transformation.
Considering the use of either underscore
or lodash
libraries to accomplish this task.