Copyright © tutorialspoint.com

Javascript String - localeCompare() Method

previous next

Advertisements


Description:

This method returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order.

Syntax:

string.localeCompare( param )

Here is the detail of parameters:

Return Value:

Example:

<html>
<head>
<title>JavaScript String localeCompare() Method</title>
</head>
<body>
<script type="text/javascript">
var str1 = new String( "This is beautiful string" );
var index = str1.localeCompare( "XYZ" );
document.write("localeCompare first :" + index ); 

document.write("<br />" ); 

var index = str1.localeCompare( "AbCD ?" );
document.write("localeCompare second :" + index ); 

</script>
</body>
</html>

This will produce following result:

localeCompare first :-1
localeCompare second :1  

To understand it in better way you can Try it yourself.


previous next

Copyright © tutorialspoint.com