Extract day, month, year from a YYYY-DD-MM string in Javascript

  • A+

I am finding the best solution for extracting day, month, year from string with YYYY-DD-MM in Javascript:

Extract from:


To object:

{ day: 25, month: 01, year: 2019 }

What is the best way to do it. Thank in advance!


You could split, destructure and return a new object.

const getDate = string => (([year, day, month]) => ({ day, month, year }))(string.split('-'));  console.log(getDate('2019-25-01'));


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: