Sorting String in JavaScript
The localeCompare()
method returns a number indicating whether a reference string comes before, or after, or is the same as the given string in sort order.
users.sort((a, b) => a.firstname.localeCompare(b.firstname));
The localeCompare()
method returns a number indicating whether a reference string comes before, or after, or is the same as the given string in sort order.
users.sort((a, b) => a.firstname.localeCompare(b.firstname));