title: get value out of really nested json array on javascript
body: <p>how do I get values out of deeply nested json array.<br/>
  I need to get all pairs of (nameValue and value) from below json</p>
  
  <pre><code>  var json = [{
                  name: 'Firstgroup',
                  elements: [{
                      name: 'Field1',
                      elements: [{
                          name: 'country32',
                          elements: [{
                              nameValue: 'city1',
                              value: 2025
                          }]
                      }]
                  },
                      {
                          name: 'Field2',
                          elements: [{
                              name: 'country22',
                              elements: [{
                                  nameValue: 'city2',
                                  value: 1875
                              }]
                          },
                              {
                                  name: 'country12',
                                  elements: [{
                                      nameValue: 'city3',
                                      value: 1810
                                  }]
                              }]
                      }]
              },
                  {
                      name: 'Secondgroup',
                      elements: [{
                          name: 'Field1',
                          elements: [{
                              name: 'country52',
                              elements: [{
                                  nameValue: 'city4',
                                  value: 1310
                              },
                                  {
                                      nameValue: 'city5',
                                      value: 1125
                                  }]
                          }]
                      },
                          {
                              name: 'Field3',
                              elements: [{
                                  name: 'country42',
                                  elements: [{
                                      nameValue: 'city6',
                                      value: 1100
                                  }]
                              }]
                          }]
                  }];
  </code></pre>
  
  <p>I managed to get the first pair by this below piece of code </p>
  
  <pre><code> function getDataProvider(array)
      {
          var dataPoint = [];
          var elements = 'elements';
          var name = 'nameValue';
          var value = 'value';
  
          var i, j, len;
  
         for (j = 0; j &lt; array.length; j++) {
             i = array[j];
             if (i[elements]) {
                 this.getDataProvider(i[elements]);
              } else {
                 dataPoint.push({
                     name: i[name],
                     value: i[value]
                 });
              }
          }
         return dataPoint;
      }    
  </code></pre>
  
  <p>how do i get all pairs out of the above json given that this json is dynamic which the depth of it is not known but it will contain pairs of (namevalue and value)</p>