get every monday in a month javascript code example

Example 1: get last date of a month javascript

var lastday = function(y,m){
return  new Date(y, m +1, 0).getDate();
}
console.log(lastday(2014,0));
console.log(lastday(2014,1));
console.log(lastday(2014,11));

Example 2: get all mondays in calendar+js

function sundaysInMonth( m, y ) {
  var days = new Date( y,m,0 ).getDate();
  var sundays = [ 8 - (new Date( m +'/01/'+ y ).getDay()) ];
  for ( var i = sundays[0] + 7; i < days; i += 7 ) {
    sundays.push( i );
  }
  return sundays;
}

alert( sundaysInMonth( 10,2012 ) ); //=> [ 7,14,21,28 ]
alert( sundaysInMonth( 10,2012 ).length ); //=> 4