title: Filter nested array of objects to array of objects
body: <p>I have an array of objects which is nested. How do I make an array of objects with this one getting values from nested properties as well? If onClick property is empty, it means there is a property called children and the parent element should not be a part of the new list. I need to loop through the children array and get the values. Please see the expected output below.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const headers = [{
      title: 'Arun',
      id: 'arunId',
      onClick: 'onClickArun'
    },
    {
      title: "George",
      id: 'georgeId',
      onClick: '',
      children: [{
          title: 'David',
          id: 'davidId',
          onClick: 'onClickDavid'
        },
        {
          title: 'Patrick',
          id: 'patrickId',
          onClick: 'onClickPatrick'
        }
      ]
    },
    {
      title: 'Mark',
      id: 'markId',
      onClick: 'onClickMark'
    }
  ];
  
  console.log(headers.map(item =&gt; {
    return {
      title: item.title,
      onClick: item.onClick
    }
  }))</code></pre>
  </div>
  </div>
  </p>
  
  <p>Expected Output:</p>
  
  <pre><code>[{
      title: 'Arun',
      onClick: 'onClickArun'
    },
    {
      title: 'David',
      onClick: 'onClickDavid'
    },
    {
      title: 'Patrick',
      onClick: 'onClickPatrick'
    },
    {
      title: 'Mark',
      onClick: 'onClickMark'
    }
  ]
  </code></pre>
  
  <p>Any help is greatly appreciated.</p>