Safari doesn't sort array of objects like others browsers
arrays, javascript, jquery, object, safari
Solution
A sort function in JavaScript is supposed to return a real number -- not true or false or a string or date. Whether that number is positive, negative, or zero affects the sort result.
Try this sort function (which will also correctly sort any strings in reverse-alphabetical order):
myArray.sort(function(a,b){
return (b.date > a.date) ? 1 : (b.date < a.date) ? -1 : 0;
});
Problem
``` var myArray = [{date:"2013.03.01"},{date:"2013.03.08"},{date:"2013.03.19"}]; ``` I tried: ``` function(a,b){ return b.date > a.date; } ``` and ``` function(a,b){ return b.date - a.date; } ``` The console.log in Chrome and Firefox give me the desired output: ``` "2013.03.19", "2013.03.08", "2013.03.01" ``` but Safari give the original sorting: ``` "2013.03.01", "2013.03.08", "2013.03.19" ``` Why?