I have an array containing strings which look like this:
["2013-1", "2013-10", "2013-11", "2013-12", "2013-2", "2013-3", "2013-4", "2014-1", "2014-2", "2014-3"]
I'm trying to sort them like so they look like:
["2013-1", "2013-2", "2013-3", "2013-4", "2013-10", "2013-11", "2013-12", "2014-1", "2014-2", "2014-3"]
I've checked out a bunch of threads on this topic but none of the solutions have worked for me.
Using this question's answer my array didn't change at all.
var myArray = ["2013-1", "2013-10", "2013-11", "2013-12", "2013-2", "2013-3", "2013-4", "2014-1", "2014-2", "2014-3"]
myArray.sort(function(a,b) {
if (isNaN(a) || isNaN(b)) {
return a > b ? 1 : -1;
}
return a - b;
});
Can't seem to find a way of doing easily doing this, any ideas of how to achieve it?