const getCurrentDate = () => {
var date = new Date().getDate();
var month = new Date().getMonth();
return date + "-" + month;
};
I want to transform the number on the month var to letters f.e " 2-8 to 2 - August "
const getCurrentDate = () => {
var date = new Date().getDate();
var month = new Date().getMonth();
return date + "-" + month;
};
I want to transform the number on the month var to letters f.e " 2-8 to 2 - August "
Create a const-array for the months and get the month-th element of it.
const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
const getCurrentDate = () => {
var date = new Date().getDate();
var month = new Date().getMonth();
return date + "-" + MONTHS[month];
};
console.log(getCurrentDate());