I am trying to sort an array which contains dates in string format (dd-mmm-yy), using the sort() function:
var array = ["1-jun-15", "1-feb-15", "1-apr-15", "1-may-15", "1-jan-15", "1-mar-15"];
array.sort(function(a, b) {
return new Date(a).getTime() - new Date(b).getTime();
});
But no success.
What's going wrong here? Here is the JSFiddle.
EDIT: While the sorting problem was solved with small correction, the primary issue is cross-browser support, which many of the answers below have differently addressed.
aandbare strings, what do you expecta.dateandb.dateto be?aandbinstead of the property accessors. Thanks!