I've been trying to create a generic function which could flatten an array of objects but am failing at every turn. JS isn't my home language. Does anyone know of any existing function which could accept an array of nested objects and output a flattened one?
Input:
const arr = [
{path:'/foo', component: SomeComponent, children: [
{path:'/one', component: SomeComponent},
{path:'/two', component: SomeComponent},
{path:'/three', component: SomeComponent},
]},
{path: '/bar', component: SomeComponent}
]
Expected output:
const flattened_arr = [
{path:'/foo', component: SomeComponent},
{path:'/foo/one', component: SomeComponent},
{path:'/foo/two', component: SomeComponent},
{path:'/foo/three', component: SomeComponent},
{path:'/bar', component: SomeComponent},
]
