title: How to push checked checkboxes values into an array?
body: <p>I'd like to push checked checkboxes values into an array, but I'm having some issue because each time I try to add it into the array it stays empty, I am probably doing something wrong but can't figure out what.</p>
  
  <p><a href="http://jsfiddle.net/fx7su2rp/689/" rel="nofollow noreferrer">http://jsfiddle.net/fx7su2rp/689/</a></p>
  
  <p><strong>HTML :</strong></p>
  
  <pre><code>&lt;input name="checkbox" value="1" type="checkbox" /&gt;
  &lt;input name="checkbox" value="2" type="checkbox" /&gt;
  &lt;input name="checkbox" value="3" type="checkbox" /&gt;
  &lt;input name="checkbox" value="4" type="checkbox" /&gt;
  &lt;button id="button" type="button"&gt;button&lt;/button&gt;
  </code></pre>
  
  <p><strong>Jquery :</strong></p>
  
  <pre><code>$(document).ready(function () {
  
    var tmp = [];
  
    $("input").each(function() {
      if ($(this).is(':checked')) {
        var checked = ($(this).val());
        tmp.push(checked);
      }
    });
  
    $('#button').on('click', function () {
          alert(tmp);
    });
  
  });
  </code></pre>
  
  <p>What am I doing wrong ?</p>