js sort() custom function how can i pass more parameters?
问题 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 attribute dinamically into the custom sort function: function compareOnOneFixedKey(a, b) { a = parseInt(a.oneFixedKey) b = parseInt(b.oneFixedKey) if (a < b) return -1 if (a > b) return 1 return 0 } arrayOfObjects.sort(compareByThisKey) should became something like: function compareOnKey(key, a, b) { a = parseInt(a[key]) b =