Open In App

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. 



Return Value: This method returns the flowing. 

Example 1: 






<script>
    // Original strings
    var str1 = new String('Geeksforgeeks'); 
  
    var index = str1.localeCompare("Geeksforgeeks");
  
    // Use of String localeCompare() Method
    console.log(index);
</script>

Output: 

0

Example 2: 




<script>
    // Original strings
    var str1 = new String('Geeksforgeeks'); 
  
    var index = str1.localeCompare("Geeks");
  
    // Use of String localeCompare() Method
    console.log(index);
</script>

Output: 

1
Article Tags :