DEV Community

John Au-Yeung
John Au-Yeung

Posted on

How to get the day of the week from the day number in JavaScript?

To get the day of the week from the day number in JavaScript, we call the toLocaleString method.

For instance, we write

const weekday = new Date().toLocaleString("en-us", { weekday: "long" });
Enter fullscreen mode Exit fullscreen mode

to call toLocaleString on a date object with the locale and an object specifying the date string returned.

We set weekday to 'long' to return the day of the week.

Top comments (0)