Question

OK I have an array as follows:

    [0 … 99]
0: Object
       date: Mon Jun 17 2013 00:00:00 GMT+0200 (CEST)
1: Object
      date: Tue Jun 18 2013 00:00:00 GMT+0200 (CEST)
2: Object
     date: Wed Jun 19 2013 00:00:00 GMT+0200 (CEST)

And so on for every month of the year throughout 3 years I'm trying to return only a month name and year for each month from my array I'm currently using the folowing Javascript to convert the object literal into an array:

scope.monthpicker = function(alldatesdumparray){
   var alldatesdump = booking.getalldates();
   var alldatesdumparray = $.map(booking.getalldates(), function(value, index) {
      return [value];
   });
      console.log(alldatesdumparray);
return alldatesdumparray;
};

and the following angularJS using ng-repeat to output the array:

        <select ng-click="monthpicker()" >
           <option class="animate-repeat" ng-repeat="returnpicker in monthpicker(alldatesdumparray)" value="{{returnpicker.date  | date:'yyyy-MMM' }}">{{returnpicker.date  | date:'yyyy-MMM' }}</option>
        </select>

Which works fine it just outoputs all the dates in my array one option per day off the month and I'd like to filter it to return only one a month?

No correct solution

OTHER TIPS

Unsure if this is a viable solution to your issue. Could you use a combination of moment.js and underscore.js?

var days = [...]// your array of dates.

var filtered = _.uniq(days, function(item) {
    return moment(item).format("YYYY MM");
});
console.log(filtered); => array containing one day per month.

This will return the first day of each month.

You can wrap model with new Date(/* ..*/)

JS

           $scope.pickers = [

               {date: new Date('Tue Feb 18 2013 00:00:00 GMT+0200 (CEST)')},
               {date: new Date('Wed Jan 19 2013 00:00:00 GMT+0200 (CEST)')},
               {date: new Date('Mon Jun 17 2013 00:00:00 GMT+0200 (CEST)')}
            ]; 

HTML

    <select >
       <option 
       ng-repeat="returnpicker in pickers" 
       >{{returnpicker.date  | date:'MMM' }}</option>
    </select>

Demo Plunker

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top