The JavaScript toLowerCase() method Converts all characters of a string to lowercase and returns a new string without changing the original.
- Used for case-insensitive comparisons
- Helps standardize user input
- Common in text formatting and data validation
- Does not modify the original string
let text = "HeLLo WoRLd";
let result = text.toLowerCase();
console.log(result);
Syntax:
str.toLowerCase();Return value:
The toLowerCase() method returns a modified version of the original string. It converts all uppercase letters into lowercase.
- Returns a new string.
- All uppercase letters are converted to lowercase.
- The original string is not changed.
[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);
[Example 2]: Converting elements of array to lowercase
The code uses map() to convert each array element to lowercase with toLowerCase(), producing ['javascript', 'html', 'css'] and logging it to the console.
let languages = ['JAVASCRIPT', 'HTML', 'CSS'];
let result = languages.map(lang => lang.toLowerCase());
console.log(result);