Last active
August 29, 2015 14:26
-
-
Save afaulkinberry/cd67ac508944a2f83f5f to your computer and use it in GitHub Desktop.
Sort Javascript Objects by Property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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