AppDividend
Latest Code Tutorials

Javascript String ToLowerCase | Javascript toLowerCase()

0

Javascript String toLowerCase() method returns the calling string value converted to lower case. The new string representing the calling string converted to a lower case.  Javascript toLowerCase() method returns the value of the string converted to lower case. The toLowerCase() function does not affect the value of the string itself.

Javascript String toLowerCase Example

String.toLowerCase() function converts the entire string to lower case. String toLowerCase() function does not affect any of the special characters, digits and the alphabets that are already in the lower case. Let’s see the following example.

// app.js

let strA = 'Avengers will be a great movie';
console.log(strA.toLocaleLowerCase());

The toLowerCase()  function does not take any arguments.

It merely returns the new string in which all the upper case letters are converted to the lower case.

Run the file by the following command.

node app

See the output below.

Javascript String toLowerCase Example

This is how you can convert Javascript Strings To Lower Case.

See the following more examples of converting all the string characters to lowercase.

// app.js

console.log('AppDividend'.toLocaleLowerCase());
console.log('KrunalLathiya'.toLowerCase());

String.prototype.toLowerCase() Tutorial

#Javascript tolowercase array

How to convert an Array of strings toLowerCase?? Well, see the following code.

let arr = [
  'MILLIE',
  'NOAH',
  'FINN',
  'SADIE'
]

let str = arr.join('~').toLowerCase()
let finArr = str.split('~')
console.log(finArr)

See the output.

➜  es git:(master) ✗ node app
[ 'millie', 'noah', 'finn', 'sadie' ]
➜  es git:(master) ✗

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

The above method could cause performance issues if you have a large amount of data in the array.

#TypeError: Cannot read property ‘toLowerCase’ of undefined

If you pass the string as an undefined then you will get this TypeError: Cannot read property ‘toLowerCase’ of undefined.

See the following code.

let str = undefined

let res = str.toLowerCase()
console.log(res)

 See the output.

➜  es git:(master) ✗ node app
/Users/krunal/Desktop/code/node-examples/es/app.js:3
let res = str.toLowerCase()
              ^

TypeError: Cannot read property 'toLowerCase' of undefined
    at Object.<anonymous> (/Users/krunal/Desktop/code/node-examples/es/app.js:3:15)

 

Finally, Javascript String ToLowerCase | Javascript toLowerCase() Tutorial is over.

Recommended Posts

Javascript String toUpperCase()

Javascript String toLocaleUpperCase()

Javascript String toLocaleLowerCase()

Javascript String replace()

Javascript String charCodeAt()

Javascript String trimStart() trimEnd()

Javascript String includes()

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.