I'll-Be-Back I'll-Be-Back - 5 months ago 32
Javascript Question

Return day of the week from int 1-7


how to return day of the week?

I have tried the following:

var i = 3;

Expected to return Wednesday which it did not work.


You need to let Moment know what the input format is. In your case, the input format is the day of the week, which Moment defines as 'e' or 'E' depending on whether you're wanting it 0-indexed or not:

moment(i, 'e').format('dddd') // if 0-6
moment(i, 'E').format('dddd') // if 1-7
Input Example Description
e     0..6    Locale day of week
E     1..7    ISO day of week

– Moment's documentation on Week year, week, and weekday tokens.