Open In App

JavaScript String toLowerCase() Method

Last Updated : 06 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

The JavaScript toLowerCase() method converts all characters in a string to lowercase, returning a new string without modifying the original.

It’s commonly used for case-insensitive comparisons, standardizing text input, or formatting strings by ensuring all characters are in lowercase.

Syntax:

str.toLowerCase();

Return value:

This method returns a new string in which all the upper-case letters are converted to lowercase.

Example 1: Converting all characters of a string to lowercase

The toLowerCase() method converts all characters in the string ‘GEEKSFORGEEKS’ to lowercase. The resulting string ‘geeksforgeeks’ is then logged to the console.

let str = 'GEEKSFORGEEKS';

// Convert to lowercase
let string = str.toLowerCase();
console.log(string); 

Output
geeksforgeeks

Example 2: Converting elements of array to lowercase

The code uses the map() method to create a new array where each element is converted to lowercase using the toLowerCase() method. The resulting array is [‘javascript’, ‘html’, ‘css’], which is then logged to the console.

let languages = ['JAVASCRIPT', 'HTML', 'CSS'];

let result = languages.map(lang => lang.toLowerCase());
console.log(result);

Output
[ 'javascript', 'html', 'css' ]

We have a complete list of Javascript string methods, to check those please go through this Javascript String Complete reference article.

Supported Browsers:

JavaScript String toLowerCase() Method- FAQs

Does toLowerCase() modify the original string?

No, toLowerCase() returns a new string and does not change the original string.

Can toLowerCase() handle special characters and numbers?

Yes, toLowerCase() only affects alphabetic characters; numbers and special characters remain unchanged.

Is toLowerCase() case-sensitive?

toLowerCase() is not case-sensitive; it converts all uppercase characters to lowercase.

Can I use toLowerCase() on non-string values?

toLowerCase() can only be used on strings. Using it on other data types will result in a TypeError.

Does toLowerCase() support Unicode characters?

Yes, toLowerCase() supports Unicode characters, converting them to their corresponding lowercase forms if available.


Next Article

Similar Reads

three90RightbarBannerImg