JSFiddle - React, Tailwind, and code Playground

by HemalathaThanigaivel

JavaScript

var last12Month = function() {
var month = new Array( "","January", "February", "March", "April", "May","June", "July", "August", "September", "October", "November", "December");
    var dates = [];
        d = new Date("02-12-2014"),
        y = d.getFullYear(),
        m = d.getMonth()+1;
   /* function padMonth(month){
        if(month<10){
            return '0'+month;
        } else {
            return month;
        }
    }*/
    console.log(m+"m")
    if( m === 12 ) {
        for(var i=1; i<13; i++) {
 
            dates.push([y , month[(i)]]);
        }
    } else {
        for(var i=m; i<m+12; i++) {
            if( (i%12) > m-1 ) {
            console.log(y-1)
                dates.push( [(y-1), month[(i+1)]]);
            } else {
                dates.push( [y , month[((i%12)+1)]]);
            }
        }
    }
 		console.log(dates);
    var values = dates.map(function(elt) { return elt[1]; });
  //  console.log(dates[values.indexOf('January')])
    return dates;
}
last12Month();