Skip to content

Instantly share code, notes, and snippets.

@filiperdt
Last active July 24, 2021 18:11
Show Gist options
  • Save filiperdt/22a1007eb240054d866c9c03630047f9 to your computer and use it in GitHub Desktop.
Save filiperdt/22a1007eb240054d866c9c03630047f9 to your computer and use it in GitHub Desktop.
Sort array by id with Array.sort() in JavaScript
items => {
items.sort((a, b) => a.id < b.id ? -1 : a.id === b.id ? 0 : 1);
// If you need your sort to work with accented characters use:
a.nome.localeCompare(b.nome)
// instead of
a.nome < b.nome ? // ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment