I'm using the built-in sort() method on an array of objects in JavaScript by providing a compare function which I think meets the needed requirements, as it returns 1, -1 or 0 whether item A compares bigger, smaller or equal to item B, respectively.
This is the code:
aData.sort(function(itemA, itemB) {
if (itemA.field1 > itemB.field1) return 1;
if (itemA.field1 < itemB.field1) return -1;
return 0;
});
This works perfectly in Iceweasel/Firefox (Version 38.6.1) on a Debian 8 VM but it's completely useless when using Chrome (Version 48.0.2564.109 (64-bit)).
No sorting whatsoever is done, the array is left completely unchanged!
I've upgraded Chrome, spent several hours searching for solutions for this problem so far but no avail.
Any ideas, guys?
Much obliged!
Copyright Notice:Content Author:「Pedro Loureiro」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/35635270/javascript-array-sort-does-not-work-in-chrome