Created
June 12, 2016 21:50
-
-
Save freewayz/2241ae4d4bdab117af73a4efa93fcfa0 to your computer and use it in GitHub Desktop.
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 myObjArray = [ | |
{ | |
name: 'peter', | |
age: 25 | |
}, | |
{ | |
name: 'john', | |
age: 15 | |
}, | |
{ | |
name: 'mary', | |
age: 49 | |
}, | |
{ | |
name: 'bush', | |
age: 8 | |
} | |
]; | |
//sort the array in ascending order of age | |
myObjArray.sort(function (first, second) { | |
return first.age > second.age; | |
}); | |
//print the our sorted array | |
myObjArray.map(function(value, index){ | |
console.log(value); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment