Skip to content

Instantly share code, notes, and snippets.

@rjcorwin
Created November 11, 2018 09:53
Show Gist options
  • Save rjcorwin/62ec76ef3c1ccc02427bde6be87566d9 to your computer and use it in GitHub Desktop.
Save rjcorwin/62ec76ef3c1ccc02427bde6be87566d9 to your computer and use it in GitHub Desktop.
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