title: Node.js loops and JSON building
body: <p>Respected ppl ....</p>
  
  <p>This is my node.js code ...
  <a href="https://gist.github.com/SkyKOG/99d47dbe5a2cec97426b" rel="nofollow">https://gist.github.com/SkyKOG/99d47dbe5a2cec97426b</a></p>
  
  <p>Im trying to parse the data of our exam results ...example ... 
  <a href="http://www.vtualerts.com/results/get_res.php?usn=1MV09IS002&amp;sem=7" rel="nofollow">http://www.vtualerts.com/results/get_res.php?usn=1MV09IS002&amp;sem=7</a></p>
  
  <p>Im getting the results ...and i am traversing back for previous seems too ... 
  All works  but traversing back happens in random ... prolly something wrong with the loops ... </p>
  
  <pre><code>            json.results = [];
  
              var output = '';
  
              var k = response.query.results.body.div.div[0].table[1].tr.length;
  
              for (var j = 1; j &lt; k; j++) {
  
                  for (var i = 0; i &lt;= 5; i++) {
                      var result_obj = {};
                      result_obj.subjects = [];
  
                      for (key in response.query.results.body.div.div[0].table[1].tr[j].td[i]) {
                          if (typeof response.query.results.body.div.div[0].table[1].tr[j].td[i].em === "undefined") {
                              continue;
                          }
  
                          var subject_obj = {};
  
                          output += "Subject : " + response.query.results.body.div.div[0].table[1].tr[j].td[i].em + " " + "\n";
  
                          var subtext = response.query.results.body.div.div[0].table[1].tr[j].td[i].em + " " + "\n";
                          subject_obj.subjectname = subtext.replace(/[(].*[)]/, "").trim();
  
                          result_obj.subjects.push(subject_obj);
                          console.log(subject_obj);
                          break;
  
                      }
  
                      console.log(result_obj.subjects);
  </code></pre>
  
  <p>I presume there is something like async concepts which need to implemented correctly to make the reordering of sems in correct order ... </p>
  
  <p>And to get the JSON in this format ... 
  <a href="https://gist.github.com/SkyKOG/3845d6a94cea3b744296" rel="nofollow">https://gist.github.com/SkyKOG/3845d6a94cea3b744296</a>
  I dont think im pushing the created objects at the right scope ... </p>
  
  <p>Kindly help in this regard .... thank you ...</p>