I have an array of strings in JS that represent dates on the format M/D/Y where M and D can have one or two digits each.
How can I write a callback function do sort this array?
I have an array of strings in JS that represent dates on the format
Share
Date.parse() (to which new Date(string) is equivalent) is not consistent across JS implementations, so I should probably manually parse the date strings first for consistency, then do exactly as Minko Gechev suggests:
As an aside, I’d argue you’re almost always better off storing Date objects rather than strings, and then formatting your Dates as strings as and when you need them for output anyway, as it makes this sort of manipulation easier, and makes your code clearer too.