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 MyArray = ["13 Jun", "09 Jun", "25 Aug", "30 Jun", "13 Aug"];
I tried to make a function for the .sort to reference, but the whole process is somewhat confusing to me. Could anyone help me out?
You’ll have to parse the strings into Date() objects, which would be straightforward enough if it weren’t for IE’s poor implementation of date string parsing. Fortunately, you can use setDate() and setMonth() with consistency across browsers, both accept numbers – 1-31 for setDate(), 0-11 for setMonth(). Setting up an object map for the month names will help.
This works for me:
I’ve set up an example for you – http://jsfiddle.net/Tw6xt/