JS Built-ins
← Date38 / 120
DategetDaybeginner

getDay() β€” Saturday is 6

πŸ“– Usage Example
const d = new Date(2024, 0, 15)  // Monday
d.getDay()  // β†’ 1
// 0=Sun, 1=Mon, …, 6=Sat

Use getDay() to retrieve the day of the week (0 = Sunday through 6 = Saturday) in local time.

Date.prototype.getDay()

Saturday has the index 6. Jan 6, 2024 was a Saturday.

Challenge: Verify that new Date(2024, 0, 6).getDay() returns 6.

πŸ’‘ Hints (1)
  • β€’ Saturday is the last day of the week in JS (index 6)