I\'m trying to sort an Array of dates from latest to oldest, and unfortunately list.sort (by default) only sorts the first number. My array looks like this:
var
You can pass a function to sort to do custom sorting:
function sortDate (a,b) {
var aa = a.split(' ');
var bb = b.split(' ');
var months = {
Jan : 1,
Feb : 2,
Mar : 3 /* you do the rest ... */
}
if (months[a[1]] > months[b[1]]) return 1;
if (months[a[1]] < months[b[1]]) return -1;
return parseInt(a[0],10) - parseInt(b[0],10);
}
MyArray.sort(sortDate);