title: TypeError: 'undefined' is not an object
body: <p>I have a currently fairly dysfunctional Javascript program that's been causing me problems. However, it throws one error that I just don't understand:</p>
  
  <pre><code>TypeError: 'undefined' is not an object (evaluating 'sub.from.length')
  </code></pre>
  
  <p>What I'm trying to do, as you can probably guess, is check the <code>length</code> of a certain "<code>from</code>" array in the <code>sub</code> dict. Here's the <a href="http://pastebin.com/RVDkJe3d" rel="noreferrer">source code for the entire function</a>, and here's the code of the loop that I think is causing the error:</p>
  
  <pre><code>console.log(afcHelper_ffuSubmissions.length); // just for debugging, returns the correct number
  for (var i = 0; i &lt; afcHelper_ffuSubmissions.length; i++) { // this whole section works fine
      var sub = afcHelper_ffuSubmissions[i];
      //console.log("THIS IS BROKEN DOWN BY LINK",afcHelper_Submissions[i]);
      if (pagetext.indexOf(afcHelper_ffuSections[sub.section]) == -1) {
          // Someone has modified the section in the mean time. Skip.
          document.getElementById('afcHelper_status').innerHTML += '&lt;li&gt;Skipping ' + sub.title + ': Cannot find section. Perhaps it was modified in the mean time?&lt;/li&gt;';
          continue;
      }
      var text = afcHelper_ffuSections[sub.section];
      var startindex = pagetext.indexOf(afcHelper_ffuSections[sub.section]);
      var endindex = startindex + text.length;
  
      console.log(sub); 
      if (typeof(sub.from) != 'undefined' &amp;&amp; sub.from.length &gt; 0) { // ** problem spot?? this is the code i recently added.
          for (var i = 0; i &lt; sub.from.length; i++) {
              mainid = sub.from[i]['id'];
              var sub = afcHelper_Submissions[mainid]; // and then it goes on from here...
  </code></pre>
  
  <p>Any ideas would be great. Frankly, I just can't see why I'm getting a <code>TypeError</code> about something that I've already explicitly checked the type of (<code>typeof(sub.from)</code>)...</p>