koehr.ing/til/2024-05-12.md

14 lines
314 B
Markdown
Raw Normal View History

2024-05-12 20:15:27 +02:00
# Sort list of strings in Javascript
[source](https://stackoverflow.com/questions/6712034/sort-array-by-firstname-alphabetically-in-javascript)
```ts
users.sort((a, b) => a.firstname.localeCompare(b.firstname))
```
or reversed order:
```ts
users.sort((a, b) => a.firstname.localeCompare(b.firstname) * -1)
```