TypeScript String localeCompare() Method

The localeCompare() is an inbuilt function in TypeScript which is used to get the number indicating whether a reference string comes before or after or is the same as the given string in sorted order. 
Syntax:
string.localeCompare( param )
Parameter: This method accept a single parameter as mentioned above and described.
- param : This parameter is a string to be compared with string object.
Return Value: This method returns the flowing.
- 0 is return, if the string is fully match.
- 1 is return, if the string is not match and the parameter value comes before the string object’s value.
- – A negative value is return, if the string is not match and the parameter value comes after the string object’s value.
Example 1:
JavaScript
| <script>     // Original strings     varstr1 = newString('Geeksforzambiatek');       varindex = str1.localeCompare("Geeksforzambiatek");      // Use of String localeCompare() Method     console.log(index); </script> | 
Output:
0
Example 2:
JavaScript
| <script>     // Original strings     varstr1 = newString('Geeksforzambiatek');       varindex = str1.localeCompare("Geeks");      // Use of String localeCompare() Method     console.log(index); </script> | 
Output:
1
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
 
				 
					


