title: Array inaccessible from within for loop - javascript
body: <p>I have a userss array that I do not appear to be able to use in any type of loop.  the array "userss" is undefined when ever I try to access it in the loop.  </p>
  
  <p>Below is the generated javascript/html.  I am sure its something simple I've just been staring at this way too long and I cannot see the mistake.  I cannot access any property from within the loop including the ones I already used just above it.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var userss = [];
  userss[ '1' ] = { id:'1', fname:'Lorem', lname: 'ipsum', uname: 'as', email: 'none@none.com', loca: '', flags: 'a', active: '1' };
  userss[ '2' ] = { id:'2', fname:'dolor', lname: 'sit', uname: 'dsit', email: 'dsit@someemail.com', loca: 'CA', flags: 'afmnopt', active: '1' };
  userss[ '3' ] = { id:'3', fname:'Test', lname: 'Testerson', uname: 'ttest', email: 'ttesterson@notreal.com', loca: 'TX', flags: 'afmnopt', active: '1' };
  function usersx(x) {
      document.getElementsByName("fname")[0].value = userss[x]["fname"];
      document.getElementsByName("lname")[0].value = userss[x]["lname"];
      document.getElementsByName("email")[0].value = userss[x]["email"];
      document.getElementsByName("user")[0].value = userss[x]["uname"];
  
  
      var rightChecks = document.querySelectorAll("[name^='right']");
  
      alert(userss[x]["flags"]);//this works
      for (x = 0 ; x &lt; rightChecks.length ; x++){ //This is the point that it breaks
          //if(true){
  
              alert(userss[x]["flags"]);//this fails "Cannot read property flags of undefined"
              var a_link = new RegExp("/" + rightChecks[x].name[5] + "/");
              //alert(userss[x]["flags"]);
              document.getElementsByName(rightChecks[x].name)[0].checked = a_link.test(userss[x]["flags"]);
              //alert(rightChecks[x].name[5]);
  
          //}
      }
  }
  </code></pre>
  
  <p>Very sorry if this ends up being a simple typo or something... I am just blind to it at this point.</p>
  
  <p>edit: I was completely oblivious to the fact I was using X for my function and for my loop counter.  Thanks folks</p>