Skip to content

Instantly share code, notes, and snippets.

@cmd-save
Created August 27, 2016 14:23
Show Gist options
  • Select an option

  • Save cmd-save/6b645acb551da372d9c8c25fa5da4b15 to your computer and use it in GitHub Desktop.

Select an option

Save cmd-save/6b645acb551da372d9c8c25fa5da4b15 to your computer and use it in GitHub Desktop.
var arrayObj=[
{name:'Aaron',age:20},
{name:'Michael',age:15},
{name:'Meriam',age:18}
]
function compare(a,b) {
if (a.age < b.age)
return -1;
if (a.age > b.age)
return 1;
return 0;
}
alert (JSON.stringify(arrayObj.sort(compare)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment