Example of this code that works normally at a specified date, which is a Saturday.
weeks=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
var today = new Date("September 24, 2022 01:15:00");
document.getElementById("current-day").innerHTML=weeks[today.getDay()-1];
<h1 id="current-day"></h1>
As stated in my title above, this code works on other days except only on Sundays, it just says Undefined, why is that?
weeks=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
var today = new Date("September 25, 2022 01:15:00");
document.getElementById("current-day").innerHTML=weeks[today.getDay()-1];
<h1 id="current-day"></h1>
>Solution :
Your code logic looks fine but the weeks array should starts with Sunday and avoid using negative 1 with getDay method.
const weeks = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
const today = new Date("September 25, 2022 01:15:00");
document.getElementById("current-day").innerHTML = weeks[today.getDay()];
<h1 id="current-day"></h1>