JavaScript String toLocaleLowerCase()
Syntax & Examples
String.toLocaleLowerCase() method
The toLocaleLowerCase() method of the String class in JavaScript converts the characters within a string to lowercase while respecting the current locale or the specified locale.
Syntax of String.toLocaleLowerCase()
There are 2 variations for the syntax of String.toLocaleLowerCase() method. They are:
toLocaleLowerCase()
This method converts the characters within the string to lowercase according to the current locale.
Returns value of type String
.
toLocaleLowerCase(locales)
Parameters
Parameter | Optional/Required | Description |
---|---|---|
locales | optional | A string with a BCP 47 language tag, or an array of such strings. This affects the locale to be used during the conversion. |
This method converts the characters within the string to lowercase according to the specified locale.
Returns value of type String
.
✐ Examples
1 Using toLocaleLowerCase() method with no arguments
In JavaScript, if no arguments are provided to the toLocaleLowerCase()
method, it converts the string to lowercase according to the current locale.
For example,
- We define a string variable
str
with the value'HELLO'
. - We use the
toLocaleLowerCase()
method with no arguments. - The result is stored in the variable
newStr
. - We log
newStr
to the console using theconsole.log()
method.
JavaScript Program
const str = 'HELLO';
const newStr = str.toLocaleLowerCase();
console.log(newStr);
Output
hello
2 Using toLocaleLowerCase() method with a single locale argument
In JavaScript, we can use the toLocaleLowerCase()
method with a specified locale to convert the string to lowercase.
For example,
- We define a string variable
str
with the value'İSTANBUL'
. - We use the
toLocaleLowerCase()
method with the argument'tr'
for Turkish locale. - The result is stored in the variable
newStr
. - We log
newStr
to the console using theconsole.log()
method.
JavaScript Program
const str = 'İSTANBUL';
const newStr = str.toLocaleLowerCase('tr');
console.log(newStr);
Output
istanbul
3 Using toLocaleLowerCase() method with multiple locale arguments
In JavaScript, we can specify multiple locales to the toLocaleLowerCase()
method to ensure proper case conversion for multiple languages.
For example,
- We define a string variable
str
with the value'HELLO'
. - We use the
toLocaleLowerCase()
method with the arguments'en-US'
and'tr'
. - The result is stored in the variable
newStr
. - We log
newStr
to the console using theconsole.log()
method.
JavaScript Program
const str = 'HELLO';
const newStr = str.toLocaleLowerCase(['en-US', 'tr']);
console.log(newStr);
Output
hello
Summary
In this JavaScript tutorial, we learned about toLocaleLowerCase() method of String: the syntax and few working examples with output and detailed explanation for each example.