I have the following array:
var times = [ ["04/11/10", "86kg"], ["05/12/11", "90kg"], ["06/12/11", "89kg"] ];
I want to list these dates and their respective weights in ascending order.
I know that you can sort arrays with sorting, and I found the following function from this About.com page , which I thought would do what I wanted:
times.sort(dmyOrdA); var dateRE = /^(\d{2})[\/\-](\d{2})[\/\-](\d{2})/; function dmyOrdA(a,b) { a = a.replace(dateRE, "$3$2$1"); b = b.replace(dateRE, "$3$2$1"); if (a > b) { return 1; } else if (a < b) { return -1; } else { return 0; } }
However, using this function, I get the following error:
a.replace is not a function
Can anyone help with my request?
Thanks in advance.
EDIT:
Looking at the previous stack overflow question, it looks like in my case, โaโ is not a string. However, I do not understand why this is so.
source share