You could, of course, just write a function based on what you already know, combined with logic for leap years:
// m is the month (January = 0, February = 1, ...) // y is the year function daysInMonth(m, y) { return m === 1 && (!(y % 4) && ((y % 100) || !(y % 400))) ? 29 : [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][m]; }
Years divisible by 4 but not divisible by 100, except when they are divided by 400, are leap years.
source share