Created
March 1, 2017 08:59
-
-
Save thomasxbanks/9fdd34e6c166e258784036f667ce967b to your computer and use it in GitHub Desktop.
Sort an array of objects
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
| 'use strict' | |
| let person = [ | |
| { name: "Person 1", age: 28 }, | |
| { name: "Person 2", age: 22 }, | |
| { name: "Person 3", age: 26 } | |
| ] | |
| person.sort(function(obj1, obj2) { | |
| // Ascending: first age less than the previous | |
| return obj1.age - obj2.age | |
| }) | |
| console.log(person) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment