title: JavaScript saving checkbox value to an array (localstorage) repeats itself during for loop
body: <p>Sorry for the not explanatory title.
  So here is my problem, im trying to save the values of checkboxes that are checked in an array(localstorage) but here is the problem:
  CODE
  HTML:</p>
  
  <pre><code>&lt;body&gt;
      &lt;div class="container"&gt;
          &lt;input type="checkbox" class="checks" value="A"&gt; A&lt;br&gt;
          &lt;input type="checkbox" class="checks" value="B"&gt; B&lt;br&gt;
          &lt;input type="checkbox" class="checks" value="C"&gt; C&lt;br&gt;
          &lt;br&gt;&lt;br&gt;
          &lt;a href="#" onclick="getValue();return false;"&gt;Get Value&lt;/a&gt;
  
          &lt;script&gt;
              function getValue() {
                  var myArray = [];
                  var checks = document.getElementsByClassName('checks');
                  var str = '';
  
                  for ( i = 0; i &lt; 3; i++) {
  
                      if ( checks[i].checked === true ) {
                          str += checks[i].value + " ";
                          myArray.push(str);
                          localStorage.setItem('str',JSON.stringify(myArray));
                      }
                  }
              }
  
          &lt;/script&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>if i check the checkbox A and B it will store the value in the localstorage but in this format <strong>["A","A B"]</strong>
  which is not right. What im expecting is <strong>["A B"]</strong>.</p>
  
  <p>Thanks in advance
  Sorry for the bad english.</p>