Sort array by firstname (alphabetically) in JavaScript [duplicate]

Shortest possible code with ES6!

users.sort((a, b) => a.firstname.localeCompare(b.firstname))

String.prototype.localeCompare() basic support is universal!

Leave a Comment