Get all months name from year in moment.js

后端 未结 9 960
执笔经年
执笔经年 2020-12-14 07:31

I want to get all months name from year in moment.js

if the year is 2011, then i want to all months name in momentjs

i have tried this below

9条回答
  •  生来不讨喜
    2020-12-14 07:54

    I needed an array with months number and months name to display them in ng-optiosn, so I extended a little bit Klaster_1's solution.

    Array.apply(0, Array(12)).map(
                        function(_,i){
                              var elem    ={};
                              elem.id     = parseInt(i+1);
                              elem.name   = moment().month(i).format('MMM'); 
                              return elem;
                        }
                  )
    

提交回复
热议问题