title: Uncaught TypeError: Cannot read property 'name' of undefined at XMLHttpRequest.xmlhttp.onload
body: <p>I'm trying to pull info from a JSON file into JavaScript and then to an HTML page but it keeps erroring when I get to a for loop that takes info from said file.</p>
  
  <pre><code> function digiLevel() {
               document.getElementById("digivice").innerHTML = "Loading...";
  
                      var xmlhttp = new XMLHttpRequest();
                      xmlhttp.onload = function() {
                          if (xmlhttp.status == 200) {
                              var textBox = document.getElementById("digivice");
  
                                var output1 = "";
                                var output2 ="";
                                var output3 = "";        
                                var digimon = xmlhttp.responseText;
  
                              console.dir(digimon);
                              digimon = JSON.parse(digimon);
                              console.dir(digimon);
  
                              output1 = "&lt;ul&gt;";
                              for (i = 0; i &lt; 6; i++) {
                                  output2 += "&lt;li&gt;" + digimon[i].name + " is a(n) " + digimon[i].level + "&lt;/li&gt;&lt;br&gt;";
                              }
                              output3 = "&lt;/ul&gt;";
  
                              textBox.innerHTML = output1 + output2 + output3;
                          }
                      }
                      xmlhttp.open("GET", "http://ec2-54-158-64-221.compute-1.amazonaws.com/Challenge9/webService.php?content=data&amp;format=json", true);
                      xmlhttp.send();
                  }
  </code></pre>
  
  <p>And it returns the Uncaught TypeError on the line </p>
  
  <pre><code> output2 += "&lt;li&gt;" + digimon[i].name + " is a(n) " + digimon[i].level + "&lt;/li&gt;&lt;br&gt;";
  </code></pre>
  
  <p>I don't see how 'name' is undefined?? Maybe I'm just blind; it's 1AM here.</p>
  
  <p>EDIT:</p>
  
  <p>Thanks for the guiding comments; I was able to find my error:</p>
  
  <p>digimon by itself didn't have a name tag of its own even with an index variable, and so I accessed the name tag by </p>
  
  <pre><code>    digimon.digivice.digimon[i].name
  </code></pre>
  
  <p>after returning digimon to the console to analyze its contents. I'm still new to working with JSON/XML so if there is a faster/more efficient/effective way to achieve the same result, do please let me know! </p>