title: Why are some values in my array undefined
body: <p>I have a for loop in php that adds a number of checkboxes on my page that look like this</p>
  
  <pre><code>&lt;input type="checkbox" name="checkbox[]"&gt;
  </code></pre>
  
  <p>I want to use javascript to check which is checked and add value in an Array</p>
  
  <pre><code>var cboxes = document.getElementsByName('checkbox[]');
  var len = cboxes.length;
  var imageArray = new Array();
  
  for (var i = 0; i &lt; len; i++) {
      if (cboxes[i].checked) {
          imageArray[i] = cboxes[i].value;
      } 
  }
  </code></pre>
  
  <p>If I have 50 boxes and click the checkbox number 2,4 and 6, loops through my array, I get the result.</p>
  
  <pre><code>for(var i = 0; i &lt; imageArray.length; i++){
      gallery.innerHTML += imageArray[i] + "&lt;br&gt;";
  }
  </code></pre>
  
  <p>--</p>
  
  <pre><code>undefined
  Correct value
  undefined
  Correct value
  undefined
  Correct value
  </code></pre>
  
  <p>If I check number 1, 2, 3 I get the result  </p>
  
  <pre><code>Correct value
  Correct value
  Correct value
  </code></pre>
  
  <p>Why do I get undefined when I skip a checkbox? How do I fix it</p>