Created
August 9, 2018 13:23
-
-
Save viveknaskar/5d089ee5e061662a999a98714807283d to your computer and use it in GitHub Desktop.
The javascript function to sort JSON objects
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
var users = [ | |
{ 'user': 'fred', 'age': 48 }, | |
{ 'user': 'barney', 'age': 36 }, | |
{ 'user': 'fred', 'age': 40 }, | |
{ 'user': 'barney', 'age': 34 } | |
]; | |
_.sortBy(users, [function(o) { return o.user; }]); | |
// => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] | |
_.sortBy(users, ['user', 'age']); | |
// => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment