title: How to separate individual object from nested tree structure
body: <p>I am having a structure like this</p>
  <pre><code>var arr = [
    {
      &quot;text&quot;: &quot;Parent 1&quot;,
      &quot;id&quot;  : &quot;1&quot;,
      &quot;nodes&quot;: [
        {
          &quot;text&quot;: &quot;Child 1&quot;,
          &quot;id&quot;  : &quot;2&quot;,
          &quot;parentid&quot;  : &quot;1&quot;,
          &quot;nodes&quot;: [
            {
              &quot;text&quot;: &quot;Grandchild 1&quot;,
              &quot;id&quot;  : &quot;4&quot;,
              &quot;parentid&quot;  : &quot;2&quot;,
            },
            {
              &quot;text&quot;: &quot;Grandchild 2&quot;,
               &quot;id&quot;  : &quot;8&quot;,
              &quot;parentid&quot;  : &quot;2&quot;,
            }
          ]
        },
        {
          &quot;text&quot;: &quot;Child 2&quot;,
          &quot;id&quot;  : &quot;10&quot;,
          &quot;parentid&quot;  : &quot;1&quot;,
        }
      ]
    },
    {
      &quot;text&quot;: &quot;Parent 2&quot;,
      &quot;id&quot;  : &quot;19&quot;,
      //no parent id
    }
  ];
  </code></pre>
  <p>I want to convert like this -</p>
  <pre><code>var arr=[
  {
       &quot;text&quot;:&quot;text1&quot;,
       &quot;id&quot;  :&quot;1&quot;,
       //no parent id
   },
  {
       &quot;text&quot;:&quot;text2&quot;,
       &quot;id&quot;  :&quot;2&quot;,
       &quot;idParent&quot;:&quot;1&quot;
   },
  {
       &quot;text&quot;:&quot;text3&quot;,
       &quot;id&quot;  :&quot;3&quot;,
       &quot;idParent&quot;:&quot;2&quot;
   },
  {
       &quot;text&quot;:&quot;text4&quot;,
       &quot;id&quot;  :&quot;4&quot;,
       &quot;idParent&quot;:&quot;1&quot;
   },
  {
       &quot;text&quot;:&quot;text5&quot;,
       &quot;id&quot;  :&quot;5&quot;,
        //no parent id
   },
  ];
  </code></pre>
  <p>How can I do this in Javascript? I want to have a conversion from nested tree object to individual objects. I am not sure how to recursive pass thorough the array of objects to get the individual ones.</p>
  <p>Thanks in advance for your help.</p>