Created
August 27, 2016 14:23
-
-
Save cmd-save/6b645acb551da372d9c8c25fa5da4b15 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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