title: Get Multiple Values from repeated nested JSON
body: <p>I'm trying to fetch values from nested JSON , and this fetching is required for all the data points (Count >1000) </p>
  
  <p>following is the JSON array i want to search on , like i'm getting <code>key</code> at level 6 from another system and based on the <code>key</code> i want to extract its value and value of its adjacent parent 
  like key  be <code>1233</code> its value will be <code>blah 6</code> its parent's value will be <code>blah 5</code> and <code>blah 4</code></p>
  
  <pre><code>{
      "collection": [{
          "id": "1:ABC",
          "key": "123",
          "value": "blah 1",
          "children": [{
              "id": "2:ABC",
              "key": "456",
              "value": "blah 2",
              "children": [{
                  "id": "3:ABC",
                  "key": "987",
                  "value": "blah 3",
                  "children": [{
                      "id": "4:ABC",
                      "key": "3445",
                      "value": "blah 4",
                      "children": [{
                          "id": "5:ABC",
                          "key": "7665",
                          "value": "blah 5",
                          "children": [{
                              "id": "6:ABC",
                              "key": "1233",
                              "value": "blah 6",
                              "children": [{
                                  "id": "7:ABC",
                                  "key": "7655",
                                  "value": "blah1 7",
                                  "children": []
                              }, {
                                  "id": "7:DEF",
                                  "key": "7655",
                                  "value": "blah2 7",
                                  "children": []
                              }]
                          }]
                      }]
                  }]
              }]
          }]
      }]
  }
  </code></pre>
  
  <p><strong>Updated</strong> : </p>
  
  <p>Approach i have implemented: </p>
  
  <pre><code>flattenJSON(actualJSONArrayObj){
      const flattenedObj: any = {};
  
      for (const level1 of actualJSONArrayObj) {
          for (const level2 of level1.children) {
              for (const level3 of level2.children) {
                  for (const level4 of level3.children) {
                      for (const level5 of level4.children) {
                          for (const level6 of level5.children) {
                                  flattenedObj[level6.key] = {
                                     level4:level4.value
                                     level5:level5.value,
                                     level6:level6.value,
                                  }
                          }
                      }
                  }
              }
          }
      }
      return flattenedObj;
    }
  
  var flattenedObj = flattenJSON(collection);
  console.log(flattenedObj['1233'].level4); //output blah 4
  </code></pre>