JavaScript String localeCompare()
JavaScript String localeCompare()
The localeCompare() method is used to compare two strings in the current locale. It will return three values. These are:-
- -1 if the string is sorted before the compareString
- 1 if the string is sorted after the compareString
- 0 if the two strings are equal
Syntax:-
Its syntax is:- string.localeCompare(compareString)
Return:-
Its return is:- 1, -1, 0
Further Explanation:-
Parameter | Description |
compareString | Required. The string to compare with. |