Created
February 26, 2017 12:08
-
-
Save samcyn/c588e6a09ab807c65ae21700be5c912e to your computer and use it in GitHub Desktop.
Sorting arrays of Objects
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
const footballers = [ | |
{ | |
name: "Rooney", | |
age: 30 | |
}, | |
{ | |
name: "Ronaldo", | |
age: 32 | |
}, | |
{ | |
name: "Martial", | |
age: 20 | |
}, | |
{ | |
name: "Messi", | |
age: 28 | |
} | |
]; | |
const players = footballers.sort(function(a,b){ return a.age - b.age}); | |
console.table(players); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment