I have an array of objects i need to sort on a custom function, since i want to do this several times on several object attributes i\'d like to pass the key name for the att
function compareOnKey(key) {
return function(a, b) {
a = parseInt(a[key], 10);
b = parseInt(b[key], 10);
if (a < b) return -1;
if (a > b) return 1;
return 0;
};
}
arrayOfObjects.sort(compareOnKey("myKey"));