Javascript String ToLowerCase

    May 18, 2020       by Pankaj Kumar

As we know, Javascript comes with a huge list of Array and String functions to perform operations on it. ToLowerCase is also a string function that converts the strings to lowercase. This method returns the value of the string converted into lower case. The toLowerCase() function does not affect the value of the string itself.

 

Javascript toLowerCase()

This method mainly convert the entire string in to lowercase. It does not affect the special characters, digits, and string which are already in lowercase. Let's have a look on the example below:

let str = 'A Quick Brown Fox';
console.log(str.toLocaleLowerCase()); // output: a quick brown fox

 

In the example, we can see with the help of toLowerCase(), a new string is returned with all the uppercase letter converted into lowercase.  

 

Javascript toLowerCase() array

In some cases we need to convert all the strings stored in an array to lower case, Let's see how we can do the same in the below example:

 

let arr = [

  'Mango',

  'Banana',

  'Orange',

  'Apple'

]

let str = arr.join('~').toLowerCase()

let finalArr = str.split('~')

console.log(finalArr) //Output:  ["mango", "banana", "orange", "apple"]

 

In the above example, we used the Javascript join() method the mixed-case array into a string, then converted it into lowercase, then Javascript split() the string back into an array.

Thank You!


WHAT'S NEW

Find other similar Articles here: