26
rated 0 times
[
32]
[
6]
/ answers: 1 / hits: 40326
/ 13 Years ago, fri, december 16, 2011, 12:00:00
I'm trying to sort an array of objects. I'd prefer not to write a custom sort method for each attribute.
Is there anyway I could extend the built-in array.sort()
method to accept an extra parameter, describing the attribute to sort on? E.g.,
array.sort(function(a, b, attr) { return a.attr - b.attr; }, 'name');
More From » sorting