Skip to content

Instantly share code, notes, and snippets.

@anderskristo
Created March 31, 2015 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anderskristo/0e393b69b510d293ff0e to your computer and use it in GitHub Desktop.
Save anderskristo/0e393b69b510d293ff0e to your computer and use it in GitHub Desktop.
Array sortByKey
function sortByKey(array, key) {
return array.sort(function(a, b) {
var x = a[key]; var y = b[key];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment