letresult = text1.localeCompare(text2); Try it Yourself » More examples below. Description ThelocaleCompare()method compares two strings in the current locale. ThelocaleCompare()method returns sort order -1, 1, or 0 (for before, after, or equal). ...
// comparing 'Python' and 'JavaScript' using localeCompare()letresult2 ='Python'.localeCompare('JavaScript'); console.log(result2); Run Code Output 0 1 In the above example, we have compared two unequal strings'Python'and'JavaScript'. Since'Python'comes after'JavaScript', the method returns1...
localeCompare() 方法返回一个数字,表示参考字符串在排序顺序中是在给定字符串之前、之后还是与之相同。在支持 Intl.Collator API 的实现中,该方法仅是调用了 Intl.Collator 方法。
The substr() method extracts a part of a string. The substr() method begins at a specified position, and returns a specified number of characters. The substr() method does not change the original string. To extract characters from the end of the string, use a negative start position. Se...
Thesubstring()method does not change the original string. If start is greater than end, arguments are swapped: (4, 1) = (1, 4). Start or end values less than 0, are treated as 0. See Also: The split() Method The slice() Method ...
Astringto be compared, in a locale-sensitive fashion, withstring. Returns A number that indicates the result of the comparison. Ifstringis “less than”target,localeCompare( )returns a number less than zero. Ifstringis “greater than”target, the method returns a number greater than zero. And...
[Microsoft.JScript.JSFunction(Microsoft.JScript.JSFunctionAttributeEnum.HasThisObject, Microsoft.JScript.JSBuiltin.String_localeCompare)] public static int localeCompare(object thisob, object thatob); Parameters thisob Object The object that this method is acting upon. thatob Object The str...
Server-side JavaScript gives string primitives and literals access to String methods. You can follow a string primitive or literal with a period and the name of a String method. The interpreter wraps the primitive or literal in a temporary object. A string object is evaluated as a single strin...
Server-side JavaScript gives string primitives and literals access to String methods. You can follow a string primitive or literal with a period and the name of a String method. The interpreter wraps the primitive or literal in a temporary object. ...
codePointLength - return the number of code points in this string Additionally, this class modifies the behaviour of the following methods: constructor - add a second parameter localeCompare - always compare using the instance's locale rather than the system's locale Formatting Two methods of the...