I have an array of objects with nested arrays, all with a similar structure. I want to flatten the array so that all objects are on the same level.
[
{
"name": "United States",
"slug": "united-states",
"states":[
{
"name": "Arizona",
"slug": "arizona"
},
{
"name": "California",
"slug": "california"
}
]
},
{
"name": "Canada",
"slug": "canada",
}
]
The resulting flattened array should look like this:
[
{
"name": "United States",
"slug": "united-states"
},
{
"name": "Arizona",
"slug": "arizona"
},
{
"name": "California",
"slug": "california"
},
{
"name": "Canada",
"slug": "canada",
}
]