I am trying to convert my array from this format
ka_layers2 = ["1-05-2019","2-05-2019" ........,"15-05-2019",.."27-05-2019"]
to something like this,
"01-05-2019","02-05-2019"
And here is my code to do so
for(i = 0; i < ka_layers2.length; i++){
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var d = new Date(ka_layers2[i]);
var day = console.log("0"+d.getDate()).slice(-2);
console.log(day);
ka_layers2arr.push(day + '-' + months[d.getUTCMonth()] + '-' + d.getUTCFullYear());
}
But this giving me a problem with "Cannot read property 'slice' of undefined"
I'm trying with answer mentioned in this question. Javascript add leading zeroes to date