title: Flatten array of objects with nested children
body: <p>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?</p>
  
  <p>Input:</p>
  
  <pre><code>const arr = [
      {path:'/foo', component: SomeComponent, children: [
              {path:'/one', component: SomeComponent},
              {path:'/two', component: SomeComponent},
              {path:'/three', component: SomeComponent},
      ]},
      {path: '/bar', component: SomeComponent}
  ]
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>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},
  ]
  </code></pre>