Skip to content
Advertisement

Create Array of Current Year and Last Year Angular

I am trying to create an Array of Years. Current year and Last Year. The following code is working however I wanted to see if there is a cleaner way of doing this?

var d = new Date();
    var currentYear = (d.getFullYear());
    var lastYear = (d.getFullYear() - 1);

    $scope.years = [
        currentYear,
        lastYear
    ];

Advertisement

Answer

Try this

   var d = new Date();
   var currentYear = d.getFullYear();
   var lastYear = currentYear - 1;
   $scope.years = [currentYear,lastYear];
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement