title: checking if the variable exists. [weird]
body: <p>I am having a weird problem here.</p>
  
  <p>I am trying to check if the variable exists</p>
  
  <p>I have</p>
  
  <pre><code>for(var i=0; i&lt;6; i++{
    if(results[(i+1)].test){
      results[(i+1)].test=i + 'test';
    }
  }
  </code></pre>
  
  <p>I know results(6).test is undefined and I need to add that extra index to check if the variable exists. I keep getting console error saying</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'test' of undefined   
  </code></pre>
  
  <p>I thought <code>if(results[(i+1)].test)</code> would check if the variable exists for me</p>
  
  <p>I also tried</p>
  
  <pre><code>if(typeof results[(i+1)].test !='undefined'){
   results[(i+1)].test=i + 'test'
  }
  </code></pre>
  
  <p>but still getting error. How do I fix this?</p>
  
  <p>Thanks a lot!</p>