I got this list of date array that I am trying to sort:
var arr = ['2017/12/16',
'2017/05/01',
'2017/04/20',
'2017/03/10',
'2017/08/12',
'2017/03/06',
'2017/02/04',
'2017/01/07',
'2016/02/08',
'2015'09/08'];
They are in yyyy/mm/dd format. I tried to use this function to sort:
arr.sort(function(a,b) {
a = a.split('/').reverse().join('');
b = b.split('/').reverse().join('');
return a > b ? 1 : a < b ? -1 : 0;
});
However, it tells me that a.split is not a function.
'2015/09/08', while it should be'2015/09/08'after replacing the inner quotation with a slash.var sorted = arr.sort();