![]() Returns a positive number if str is greater than str2.Īlert( 'Österreich'.localeCompare('Zealand') ) // -1.Returns a negative number if str is less than str2.The call str.localeCompare(str2) returns an integer indicating whether str is less, equal or greater than str2 according to the language rules: It provides a special method to compare strings in different languages, following their rules. Luckily, modern browsers support the internationalization standard ECMA-402. So, the browser needs to know the language to compare. ![]() The “right” algorithm to do string comparisons is more complex than it may seem, because alphabets are different for different languages. Here, its code is greater than anything from a to z. Some letters like Ö stand apart from the main alphabet.All lowercase letters go after uppercase letters because their codes are greater.The code for a (97) is greater than the code for Z (90). The greater code means that the character is greater. The characters are compared by their numeric code.
0 Comments
Leave a Reply. |