Categories
JavaScript Answers

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

Spread the love

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" });

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *