This JavaScript tutorial explains how to use the string method known as toLocaleLowerCase() with syntax and examples.
Description
In JavaScript, toLocaleLowerCase() is a string method that is used to convert a string to lowercase based totally on locale. Because the toLocaleLowerCase() method is a technique of the String object, it need to be invoked through a unique instance of the String class.
Syntax
In JavaScript, the syntax for the toLocaleLowerCase() technique is:
string.toLocaleLowerCase([locale]);
Parameters or Arguments
locale Optional. It is a BCP forty seven language tag or an array of such tags. A BCP 47 language tag defines a language that might also comprise a important language code as nicely as an extension. If this parameter is now not provided, the toLocaleLowerCase() method will use the host environment’s contemporary locale.
Returns
The toLocaleLowerCase() method returns a string transformed to lowercase the usage of a precise locale.
Note
The toLocaleLowerCase() technique does now not trade the cost of the unique string.
Example
Let’s take a look at an example of how to use the toLocaleLowerCase() method in JavaScript.
For example:
var totn_string = 'TechOnTheNet';
console.log(totn_string.toLocaleLowerCase());
In this example, we have declared a variable referred to as totn_string that is assigned the string value of ‘TechOnTheNet’. We have then invoked the toLocaleLowerCase() method of the totn_string variable to convert the string to lowercase.
We have written the output of the toLocaleLowerCase() method to the net browser console log, for demonstration purposes, to show what the toLocaleLowerCase() method returns.
The following will be output to the net browser console log:
techonthenet
In this example, the toLocaleLowerCase() approach used the host’s cutting-edge locale and transformed the string ‘TechOnTheNet’ to lowercase and again a string value of ‘techonthenet’.
Specifying a Locale Parameter
Instead of the usage of the host’s present day locale, you can also specify a BCP 47 language tag for the locale parameter that will be used to convert the string to lowercase.
For example:
var totn_string = 'CAFÉ';
console.log(totn_string.toLocaleLowerCase('en-US'));
The following will be output to the net browser console log:
café
In this example, the toLocaleLowerCase() method used a locale parameter of ‘en-US’ to convert the string to lowercase using US English. The toLocaleLowerCase() technique back a string cost of ‘café’.
Leave a Review