JavaScript string.toLocaleLowerCase() Method

Shubham Vora Jan 30, 2023
  1. Syntax of JavaScript string.toLocaleLowerCase():
  2. Example Codes: Use the string.toLocaleLowerCase() Method to Convert a String to Lowercase
  3. Example Codes: Use the string.toLocaleLowerCase() Method to Specify a locale for the New String
JavaScript string.toLocaleLowerCase() Method

The string.toLocaleLowerCase() method converts the characters of a given string into lowercase according to any locale-specific case mappings. The host’s current locale is set as the default locale.

In the toLocaleLowerCase() method, there is no parameter. However, users can choose from BCP 47 language tags to set a locale parameter.

Syntax of JavaScript string.toLocaleLowerCase():

referenceString.toLocaleLowerCase();
referenceString.toLocaleLowerCase(locale);

Parameter

locale To specify a locale that should be used to convert the characters of a string into lowercase.

Return

It returns the given string in lowercase based on the locale-specific case mappings.

Example Codes: Use the string.toLocaleLowerCase() Method to Convert a String to Lowercase

The string.toLocaleLowerCase() method can convert a string to lowercase without any parameter. If some strings are not converting according to locale-specific case mapping, we can choose from BCF 47 language tags to specify a locale parameter.

In this example, we have not passed any parameter in the string.toLocaleLowerCase() method.

let string = 'CAFÉ';
let lwStr = string.toLocaleLowerCase();
console.log(lwStr);

Output:

café

Example Codes: Use the string.toLocaleLowerCase() Method to Specify a locale for the New String

We might get different outputs while working on a host of distant locations or using an old-version browser. Hence, you can specify a locale parameter by selecting it from the BCF 47 language tags.

In the example below, we have passed an fr-FR (French Locale) to the locale parameter in the string.toLocaleLowerCase() method to see the output.

var string = 'Select Français or Español language.';
let frStr = string.toLocaleLowerCase('fr-FR');
console.log(frStr);

Output:

select français or español language.

The string.toLocaleLowerCase() method converts the text of a string into lowercase according to the locale-specific case mappings. By default, the method will use the locale of the host.

Although string.toLocaleLowerCase() and string.toLowerCase() give similar output, both the methods are used for different purposes.

Author: Shubham Vora
Shubham Vora avatar Shubham Vora avatar

Shubham is a software developer interested in learning and writing about various technologies. He loves to help people by sharing vast knowledge about modern technologies via different platforms such as the DelftStack.com website.

LinkedIn GitHub

Related Article - JavaScript String