why Javascript take the 3rd arrayList in this subject :
var today = new Date();
var day=today.getDate();
var daylist = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
console.log("Today is : " + daylist[day] + ".");
/**Today is : Tuesday.*//
I try to take the reason why the 3rd Arraylist
2
Answers
The getDate() function returns today’s date like 2. so it always returns Tuesday.
To get today’s day you should use the getDay() function.
In JavaScript,
getDay()
returns a day-of-week number (0 for Sunday, 1 for Monday, etc.), and yourdaylist
array is indexed using this value, making it access the corresponding day name.