Javascript array sort not working on iOS


#1

I have this sample code (that renders perfectly on Android) sorting an array. On iOS, the results are not correct (see pictures attached):

var items = [{fid:"1498305528359"},{fid:"1498907259659"},{fid:"1499104313002"}]

items.sort(function(a,b) {return (a.fid > b.fid) ? 1 : ((b.fid > a.fid) ? -1 : 0);} );
items.reverse();  
                   
alert(items[0].fid+", "+items[1].fid+", "+items[2].fid)


#2

Hey, I see you are comparing strings lexicographically, perhaps you want to compare their numeric values?


#3

I’ve tried both ways with the same results.