Get all months name from year in moment.js
There happens to be a function for that:
moment.monthsShort()
// ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
Or the same using manual formatting:
Array.apply(0, Array(12)).map(function(_,i){return moment().month(i).format('MMM')})
I guess you want to display all names utilizing Moment.js locale data, which is a reasonable approach.
if the year is 2011, then i want to all months name in momentjs
Why does the year matter? Month names don't change.
You could get month names from Moment like so:
var m = moment();
for (var i = 0; i < 12; i++) {
console.log(m.months(i).format('MMMM'));
}
Using moment.js you have the following methods:
moment.months() // long names
returns:
[ 'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December' ]
and
moment.monthsShort() // short names
returns:
["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]