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.
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
.
In JavaScript, if no arguments are provided to the toLocaleLowerCase()
method, it converts the string to lowercase according to the current locale.
For example,
str
with the value 'HELLO'
.toLocaleLowerCase()
method with no arguments.newStr
.newStr
to the console using the console.log()
method.const str = 'HELLO';
const newStr = str.toLocaleLowerCase();
console.log(newStr);
hello
In JavaScript, we can use the toLocaleLowerCase()
method with a specified locale to convert the string to lowercase.
For example,
str
with the value 'İSTANBUL'
.toLocaleLowerCase()
method with the argument 'tr'
for Turkish locale.newStr
.newStr
to the console using the console.log()
method.const str = 'İSTANBUL';
const newStr = str.toLocaleLowerCase('tr');
console.log(newStr);
istanbul
In JavaScript, we can specify multiple locales to the toLocaleLowerCase()
method to ensure proper case conversion for multiple languages.
For example,
str
with the value 'HELLO'
.toLocaleLowerCase()
method with the arguments 'en-US'
and 'tr'
.newStr
.newStr
to the console using the console.log()
method.const str = 'HELLO';
const newStr = str.toLocaleLowerCase(['en-US', 'tr']);
console.log(newStr);
hello
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.