title: Uncaught TypeError: Cannot read property x of undefined
body: <p>Getting the above error in Chrome console while the actual script works and generates the right output, wonder how I can get rid of this error and what is causing it.</p>
  
  <p>JSFiddle: <a href="http://jsfiddle.net/wJUeP/" rel="nofollow">http://jsfiddle.net/wJUeP/</a></p>
  
  <p>HTML Code:</p>
  
  <pre><code>&lt;ul id="menu"&gt;&lt;/ul&gt;
  &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>JS Code:</p>
  
  <pre><code>$(function(){
  var data = [{"weekending":"09\/10\/2013","jobs":[{"jobnumber":"1001","jobaddress":"Test1001","employees":[{"employeenumber":"1","name":"James Blabla","class":"FHM","notes":"xx","nt-wkmon":"2","t12-wkmon":"5","dt-wkmon":"4","status-wkmon":"Public Holiday","startTime-wkmon":"4","finishTime-wkmon":"6","nt-wktue":"7"}]},{"jobnumber":"1002","jobaddress":"Test1002","employees":[{"employeenumber":"1","name":"Cameron Le","class":"FHQ","notes":"xx","nt-wkmon":"2","t12-wkmon":"5","dt-wkmon":"4","status-wkmon":"Public Holiday","startTime-wkmon":"4","finishTime-wkmon":"6","nt-wktue":"7"},{"employeenumber":"2","name":"David Le","class":"FHQ","notes":"xx","nt-wkmon":"2","t12-wkmon":"5","dt-wkmon":"4","status-wkmon":"Public Holiday","startTime-wkmon":"4","finishTime-wkmon":"6","nt-wktue":"7"}]},{"jobnumber":"1003","jobaddress":"Test1003","employees":[{"employeenumber":"1","name":"Nick G","class":"sdf","notes":"sdf","nt-wkmon":"2","t12-wkmon":"5","dt-wkmon":"4","status-wkmon":"Public Holiday","startTime-wkmon":"4","finishTime-wkmon":"6","nt-wktue":"7"}]}]}];
  
  for(var i = 0, j = data[0].weekending.length; i&lt;j; i++) {
      rootMenu = data[0].jobs[i];
      $("#menu").append("&lt;li id='job_" + rootMenu.jobnumber + "'&gt;" + rootMenu.jobnumber);
      if(rootMenu.hasOwnProperty("employees")) {
          $("#menu").append("&lt;ul id='employees_job_" + rootMenu.jobnumber + "'&gt;");
          for(var n = 0, m = rootMenu.employees.length; n&lt;m; n++) {
              var subMenu = rootMenu.employees[n];
              if(subMenu.hasOwnProperty("name")) {
                  $("#employees_job_" + rootMenu.jobnumber).append("&lt;li&gt;" + subMenu.name + "&lt;/li&gt;");
              }
          }
          $("#menu").append("&lt;/ul&gt;");
      } else {
          $("#menu").append("&lt;/li&gt;");
      }
  }
  });
  </code></pre>
  
  <p>Note: I'm still in the development stage of my application and I have the flexibility to change and manipulate the data structure, if embedded JSON data looks bad I can change it, actual data is stored in a XML file and then read by PHP and outputted as JSON.</p>