Skip to content

Instantly share code, notes, and snippets.

@JakeCoxon
Created May 3, 2013 17:33
Show Gist options
  • Save JakeCoxon/5511725 to your computer and use it in GitHub Desktop.
Save JakeCoxon/5511725 to your computer and use it in GitHub Desktop.
Sort an array by multiple fields
// Sort an array
array.sort(function(A, B) {
var a, b;
return (((a = A.field1) > (b = B.field1)) - (b > a)) || // Sort by field1
(((a = A.field2) > (b = B.field2)) - (b > a)) // Sort by field2
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment