here is code explanation convert string 7thJun1969 to date 1969-06-07 in JavaScript Here I use the slice method to solve the problem shine.com question
<script>
// function to change the formate of date
function changeDateFormate(givenDate){
let year = givenDate.slice(-4);
let month = givenDate.slice(-7).slice(0,-4);
let day = givenDate.slice(0,-9);
let obj = {
Jan : "01",
Feb : "02",
Mar : "03",
Apr : "04",
May : "05",
Jun : "06",
Jul : "07",
Aug : "08",
Sep : "09",
Oct : "10",
Nov : "11",
Dec : "12"
}
if(day < 10){
day = 0+""+day;
}
let finalDate = year + "-" + obj[month] + "-" +day;
return finalDate;
}
// code output
console.log("1stOct1948");
</script>