Last active
July 24, 2021 18:11
-
-
Save filiperdt/22a1007eb240054d866c9c03630047f9 to your computer and use it in GitHub Desktop.
Sort array by id with Array.sort() in JavaScript
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
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