Skip to content

Instantly share code, notes, and snippets.

@madisonmay
Last active December 18, 2015 07:39
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 madisonmay/5748329 to your computer and use it in GitHub Desktop.
Save madisonmay/5748329 to your computer and use it in GitHub Desktop.
Sorts an array in javascript by the given property
Array.prototype.sortBy = function(p){
//sorts an array of objects by property p
return this.sort(function(a,b){
return (a[p] > b[p]) ? 1 : (a[p] < b[p]) ? -1 : 0;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment