Skip to content

Instantly share code, notes, and snippets.

@freewayz
Created June 12, 2016 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freewayz/2241ae4d4bdab117af73a4efa93fcfa0 to your computer and use it in GitHub Desktop.
Save freewayz/2241ae4d4bdab117af73a4efa93fcfa0 to your computer and use it in GitHub Desktop.
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