Created
March 5, 2017 13:48
-
-
Save yashikagarg13/f3488dab8f1096451cc5ca2e790aa96b to your computer and use it in GitHub Desktop.
Sort array of objects by key
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 arrOfObjects = [ | |
{name: "Yashika", age: 27}, | |
{name: "Ketan", age: 28}, | |
{name: "Rahul", age: 13}, | |
{name: "Shivani", age: 20}, | |
{name: "Ankit", age: 45}, | |
{name: "Rashmi", age: 16}, | |
{name: "Vijay", age: 70}, | |
]; | |
var result = arrOfObjects.sort(function (a, b) { | |
return a.age - b.age; | |
}); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment