title: Javascript / jQuery: How to check if date is last day of month
body: <p>I have the following code (shortened) which creates the dates of a month while looping through an array. </p>
  
  <p>This works fine so far but I am struggling to <strong>stop it if it reaches the last day of a month</strong>. 
  I am using this to dynamically add table rows to an HTML table and as the array is set to end at 31 it always starts with the next month when the set month has less than 31 days. The cells in my table then show e.g. ...<code>28, 29, 1, 2</code> for the February column. </p>
  
  <p>Can someone tell me how I can check whether <code>day1</code>, <code>day2</code> or <code>day3</code> are the last day of the month and if set them to '' ?</p>
  
  <p>My thought was that the following will give me the last day of a month but I couldn't find a way to work this in here and to use it properly for the comparisons: </p>
  
  <pre><code>var d = new Date(y, m+1, 0);
  </code></pre>
  
  <p><strong>My JS (shortened):</strong> </p>
  
  <pre><code>$('#btnStart').on('click', function(){
      var date1, day1;
      var date2, day2;            
  
      var d = 0;
      var m = 0;  // user input
      var y = 2015; // user input
      for (d = 0; d &lt;= 30; d++) {
          date1 = new Date(y, m, d+1);
          day1 = date1.getDate();
          date2 = new Date(y, m+1, d+1);
          day2 = date2.getDate();
      }
  });
  </code></pre>
  
  <p><strong>Update:</strong> This is only needed within a given year so it will never go from December to January.</p>
  
  <p>Many thanks for any help with this, 
  Mike</p>