title: Angular 8 - How to filter nested JSON and return result in new array
body: <p>I am getting below JSON from API response inside the <code>fetchdataFromAPI</code> function.</p>
  <p>I want to find distinct regions from all children of the below JSON objects and need to create new a filtered array of objects same as my expected output.</p>
  <p>I have the below code with JSON from which I tried to get my expected output but anyhow it is returning only objects of the first children, not all children objects.</p>
  <p>Can anyone please help me to correct my code and provide my expected response from the below function?</p>
  <pre class="lang-js prettyprint-override"><code>fetchdataFromAPI() {
      const data = [
        {
          &quot;name&quot;: &quot;Africa&quot;,
          &quot;children&quot;: [
            {
              &quot;name&quot;: &quot;Test1&quot;,
              &quot;region&quot;: &quot;1UL Africa&quot;
            },
            {
              &quot;name&quot;: &quot;Test2&quot;,
              &quot;region&quot;: &quot;South Africa&quot;,
            },
            {
              &quot;name&quot;: &quot;Test3&quot;,
              &quot;region&quot;: &quot;1UL Africa&quot;,
            }
          ]
        },
        {
          &quot;name&quot;: &quot;Europe&quot;,
          &quot;children&quot;: [
            {
              &quot;name&quot;: &quot;Test4&quot;,
              &quot;region&quot;: &quot;1UL Africa&quot;
            },
            {
              &quot;name&quot;: &quot;Test5&quot;,
              &quot;region&quot;: &quot;Test Europe&quot;
            }
          ]
        }
      ];
      this.dataService.setBUSubRegionList(this.processRegion(data));
    }
  
   processRegion(buRegionList) {    
      const list = [];  
      for (const buReg of buRegionList) {
        const tempBu = buReg;
        if (buReg.children) {
          let i = 0;
          for (const buRegion of buReg.children) {        
            if (!buRegion.region) {          
              tempBu.children.splice(i, 1);
            }
            i++;
          }
        }
        list.push(tempBu);
      } 
      return list;
    }
  </code></pre>
  <p>Below is my expected output from the above JSON.</p>
  <pre class="lang-js prettyprint-override"><code>newData = [
     {
        &quot;name&quot;: &quot;Test1&quot;, 
        &quot;region&quot;: &quot;1UL Africa&quot;        
     },
     {
        &quot;name&quot;: &quot;Test2&quot;,
        &quot;region&quot;: &quot;South Africa&quot;,           
     },
     {
        &quot;name&quot;: &quot;Test5&quot;,
        &quot;region&quot;: &quot;Test Europe&quot;       
     },
  ];
  </code></pre>