With ES6 arrow functions, you can further write just one line of concise code (excluding variable declaration).
Eg.:
var isDescending = true; //set to false for ascending
console.log(["8/2/2020","8/1/2020","8/13/2020", "8/2/2020"].sort((a,b) => isDescending ? new Date(b).getTime() - new Date(a).getTime() : new Date(a).getTime() - new Date(b).getTime()));
_x000D_
Since time does not exists with the above dates, the Date object will consider following default time for sorting:
00:00:00
The code will work for both ascending and descending sort.
Just change the value of isDescending
variable as required.