String.prototype.localeCompare

Determines whether two strings are equivalent in the current locale.

Syntax

localeCompare(another)

Parameters

Return value

A number, which indicates whether the target string comes before (negative), after (positive), or is equivalent to (zero) the string passed as the argument, in sort order.

Examples

"lava".localeCompare("volcano")
-1
["čokolada", "aronija", "džem"].sort((a, b) => a.localeCompare(b))
["aronija", "čokolada", "džem"]
// Compare with no localeCompare:
["čokolada", "aronija", "džem"].sort()
["aronija", "džem", "čokolada"]