Created
November 11, 2018 09:53
-
-
Save rjcorwin/62ec76ef3c1ccc02427bde6be87566d9 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 items = [ | |
{ name: 'Edward', value: 21 }, | |
{ name: 'Sharpe', value: 37 }, | |
{ name: 'And', value: 45 }, | |
{ name: 'The', value: -12 }, | |
{ name: 'Magnetic', value: 13 }, | |
{ name: 'Zeros', value: 37 } | |
] | |
// sort by value | |
items.sort((a, b) => a.value - b.value) | |
console.log(items) | |
// sort by name | |
items.sort((a, b) => a.name.toUpperCase() < b.name.toUpperCase() ? -1 : 1) | |
console.log(items) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment