To get the day of a month, use the Date() object, passing it the year, the month + 1 , and zero for the day as parameters. The Date object can contain the Day of the month.
var month = 0;
var day = new Date(2023, month + 1, 0);
console.log(day.toString());