Check if checkbox checked jquery

Show hide input field on the basis of checkbox hidden or visible

HTML

<input name="checkbox" value="1" type="checkbox" />
<input name="checkbox" value="2" type="checkbox" />
<input name="checkbox" value="3" type="checkbox" />
<input name="checkbox" value="4" type="checkbox" />
<button id="button" type="button">button</button>

JavaScript

$(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);
  });
  
});