Skip to content

Instantly share code, notes, and snippets.

@afaulkinberry
Last active August 29, 2015 14:26
Show Gist options
  • Save afaulkinberry/cd67ac508944a2f83f5f to your computer and use it in GitHub Desktop.
Save afaulkinberry/cd67ac508944a2f83f5f to your computer and use it in GitHub Desktop.
Sort Javascript Objects by Property
//property = first_name
function compare(a,b) {
if (a.first_name < b.first_name)
return -1;
if (a.first_name > b.first_name)
return 1;
return 0;
}
//object array = data.records
var sorted = data.records.sort(compare);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment