The localeCompare () method is defined and used to compare two strings in a specific local order. The stringObject. localeCompare (target) parameter describes the strings in which the target object must be compared with the stringObject in a specific local order. The return value indicates the number of results to be compared... SyntaxHigh
LocaleCompare () method
Definition and usage
Compares two strings in a specific local order.
Syntax
StringObject. localeCompare (target)
Parameter description
Target string to be compared with stringObject in a specific local order.
Return Value
Number of the comparison result. If stringObject is smaller than target, localeCompare () returns a number smaller than 0. If the value of stringObject is greater than target, this method returns a value greater than 0. If the two strings are equal or there is no difference according to the local sorting rules, this method returns 0.
Test 1:
Var str = "Beijing ";
Var var2 = "Beijing ";
Var res = str. localeCompare (var2 );
Console. log (res );
Output 0, equal
Test 2:
Var str = "Monday ";
Var var2 = "Tuesday ";
Var res = str. localeCompare (var2 );
Console. log (res );
Output 1