Make sure to consult the manual for .getDay()
:
The integer value returned by getDay()
corresponds to the day of the week: 0
for Sunday, 1
for Monday, 2
for Tuesday, and so on.
Understanding this explanation is key. The Date
object acquires the current date and time from the system, providing essential details about Day, Month, Year, Week, Week number, and more. Additionally, here's a useful tool for debugging your code:
var today = new Date();
// Outputs `Tue Jan 05 2016 16:30:25 GMT+0000 (GMT Standard Time)`.
var day = today.getDay();
// Returns `2`, indicating it is Tuesday.
var daylist = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
//Define your array.
console.log("Today is : " + daylist[day] + ".");
// This translates to `daylist[2]`, where Tuesday is at index `2` in the array.