JavaScript String toLowerCase() Method (original) (raw)
Last Updated : 06 Sep, 2024
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.
JavaScript `
let str = 'GEEKSFORGEEKS';
// Convert to lowercase let string = str.toLowerCase(); console.log(string);
`
**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.
JavaScript `
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.