Javascript – How to get the day of the week from the day number in JavaScript


Given dayNumber is from 06 representing MondaySunday respectively.

Can the Date / String objects be used to get the day of the week from dayNumber?

Best Solution

A much more elegant way which allows you to also show the weekday by locale if you choose to is available starting the latest version of ECMA scripts and is running in all latest browsers and node.js:

console.log(new Date().toLocaleString('en-us', {  weekday: 'long' }));