Skip to content
Advertisement

How to sort the string of date format in an array

Input

JavaScript

output 22 March 2015, 09 May 2015, 18 August 2015, 25 December 2015, 25 jun 2016

Advertisement

Answer

Subtracting 2 dates returns the difference between the two dates in milliseconds if a date is smaller than b returns negative values a will sorted to be a lower index than b.

JavaScript
Advertisement