Skip to content

Instantly share code, notes, and snippets.

@michiel
Created August 26, 2015 14:17
Show Gist options
  • Save michiel/8e4372ad553ce5a8444f to your computer and use it in GitHub Desktop.
Save michiel/8e4372ad553ce5a8444f to your computer and use it in GitHub Desktop.
Sort array of objects on key
var key = 'name';
return objs.sort(function (a, b) {
if (a[key] > b[key]) {
return asc ? 1 : -1;
} else if (a[key] < b[key]) {
return asc ? -1 : 1;
} else {
return 0;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment