JavaScript Get all mondays in the year mondays per year,happy mondays year,mondays in a year,

Just loop through the year instead of the month. The code is the same as yours, it works fine. just changed month -> year and getMonth() -> getYear()

var d = new Date(),
    year = d.getYear(),
    mondays = [];

d.setDate(1);

// Get the first Monday in the month
while (d.getDay() !== 1) {
    d.setDate(d.getDate() + 1);
}

// Get all the other Mondays in the month
while (d.getYear() === year) {
    var pushDate = new Date(d.getTime());
    mondays.push(pushDate.getDate() + '-' + (pushDate.getMonth()+1) + '-' + pushDate.getFullYear());
    d.setDate(d.getDate() + 7);
}
Answer:1

This is just an alternative, it uses a simpler method of getting the first day of the month.

// Get all Mondays in year from provided date
// Default today's date
function getMondays(d) {
  // Copy d if provided
  d = d ? new Date(+d) : new Date();
  // Set to start of month
  d.setDate(1);
  // Store end year and month
  var endYear = d.getFullYear() + 1;
  var endMonth = d.getMonth();

  // Set to first Monday
  d.setDate(d.getDate() + (8 - (d.getDay() || 7)) % 7);
  var mondays = [new Date(+d)];

  // Create Dates for all Mondays up to end year and month
  while (d.getFullYear() < endYear || d.getMonth() != endMonth) {
    mondays.push(new Date(d.setDate(d.getDate() + 7)));
  }
  return mondays;
}

// Get all Mondays and display result
// SO console doensn't show all results
var mondays = getMondays();
mondays.forEach(function(mon) {
  console.log(mon.toLocaleString(void 0, {
    weekday: 'short',
    day: 'numeric',
    month: 'short',
    year: 'numeric'
  }));
});

// Count of Mondays, not all shown in SO console
console.log('There are ' + mondays.length + ' Mondays, the first is ' + mondays[0].toString())
Answer:2

I am using an onClick function and trying to also pass an object with it. I need the object to make the function work. But for some reason it is giving me this error. The error is coming from the ...

I am using an onClick function and trying to also pass an object with it. I need the object to make the function work. But for some reason it is giving me this error. The error is coming from the ...

I have 2 challenges, On page load, I would like to show a warning saying that "caps is on". Still the user press the shift + key or Caps on + key - I would like to through error. I search in google ...

I have 2 challenges, On page load, I would like to show a warning saying that "caps is on". Still the user press the shift + key or Caps on + key - I would like to through error. I search in google ...

I am currently setting up a Heroku deployment. Everything works fine when it is run locally but I get the following error from Heroku. at=info method=GET path="/" host=pure-cliffs-68507.herokuapp.com ...

I am currently setting up a Heroku deployment. Everything works fine when it is run locally but I get the following error from Heroku. at=info method=GET path="/" host=pure-cliffs-68507.herokuapp.com ...

  1. internal server error 500
  2. internal server error meaning
  3. internal server error uber eats
  4. internal server error /swagger/v1/swagger.json
  5. internal server error wordpress
  6. internal server error 43531
  7. internal server error code
  8. internal server error 500 meaning
  9. internal server error spectrum
  10. internal server error api gateway
  11. internal server error 43549
  12. internal server error heroku
  13. internal server error nextcloud
  14. internal server error flask
  15. internal server error league of legends
  16. internal server error apex
  17. internal server error message
  18. internal server error 500 wordpress
  19. internal server error salesforce
  20. internal server error yahoo mail

I am using the following angular binding on an input: <li data-ng-repeat="value in model.Values"> <input type="number" data-required data-min="-10" data-max="10" ...

I am using the following angular binding on an input: <li data-ng-repeat="value in model.Values"> <input type="number" data-required data-min="-10" data-max="10" ...

  1. conditional value input
  2. ng-class conditional input value
  3. html input value conditional
  4. angular input value conditional
  5. angular 2 conditional input value
  6. angularjs conditional input value