"fcc" and "Fcc" gives -1 because capital "F" is greater than small "f". The comparison above gives 1 because, in the English locale, ba n in banana comes after ba c in back.Ĭonst compareValue1 = string1.localeCompare(string2)Ĭonst compareValue2 = string1.localeCompare(string3)Ĭomparing "fcc" and "fcc" gives 0 because they are equal in order. It gives -1 because, in the English locale, h in hello comes before w in the world (w is further down in the alphabetical order than h)Īnother example: const string1 = "banana" Here are some examples comparing two strings: const string1 = "hello"Ĭonst compareValue = string1.localeCompare(string2) 0 if string1 and string2 are equal in the alphabetical order.-1 if string1 is smaller (lower in the alphabetical order) than string2.1 if string1 is greater (higher in the alphabetical order) than string2.Here's the syntax: string1.localeCompare(string2) You can use the localeCompare method to compare two strings in the current locale. How to Compare Strings Using localeCompare I'll show you two of them in this article.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |