Friday, December 27, 2024
Google search engine
HomeLanguagesJavascriptJavaScript String toLowerCase() Method

JavaScript String toLowerCase() Method

Javascript str.toLowerCase() method converts the entire string to lowercase. This method does not affect any of the special characters, digits, and the alphabet that is already 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: Below is an example of the String toLowerCase() Method.

JavaScript




function func() {
    let str = 'GEEKSFORGEEKS';
    let string = str.toLowerCase();
    console.log(string);
}
func();


Output: 

neveropen

Example 2: In this example, the method toLowerCase() converts all the upper case alphabets into lower case alphabets without affecting the special characters, digits, and all those characters that are already in the lower case.

JavaScript




// JavaScript Program to illustrate
//  toLowerCase() method
 
function func() {
 
    // Original string
    let str = 'It iS a Great Day.';
 
    // Converting to lower case
    let string = str.toLowerCase();
    console.log(string);
}
 
func();


Output: 

it is a great day.

Example 3: In this example, the method toLowerCase() converts all the upper case alphabets into lower case alphabets without affecting the special characters, digits, and all those characters that are already in lower case.

JavaScript




// JavaScript Program to illustrate
//  toLowerCase() method
 
function func() {
 
    //Original string
    let str = 'It iS a 5r&e@@t Day.';
 
    //Converting to lower case
    let string = str.toLowerCase();
    document.write(string);
}
 
func();


Output: 

it is a 5r&e@@t day.

Example 4: In this example, we create an array of languages with elements ‘JAVASCRIPT’, ‘HTML’, and ‘CSS’. It uses map() and toLowerCase() to convert each element to lowercase.

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.

Supported Browser:

  • Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 3 and above
  • Opera 3 and above
  • Safari 1 and above

RELATED ARTICLES

Most Popular

Recent Comments