In this tutorial, you will learn about JavaScript string toLowerCase() method and how to convert string characters into lowercase using this method.
JavaScript String toLowerCase() is a built-in method that is used to convert string characters into lowercase.
JavaScript str.toLowerCase() method converts the characters of a string into lower case characters.
Note that, this method does not affect any of the special characters, digits, and string characters that are already in lowercase.
The following syntax represents the string.toLowerCase() method:
string.toLowerCase();
Here,
Let’s take a look at the example:
let str = 'A Quick Javascript Tutorial';
console.log(str.toLowerCase()); // output: a quick javascript tutorial
In this example, you can see all the uppercase string characters converted into lowercase with the help of javascript toLowerCase() method.
How to convert a string to lowercase which is stored in an array?. You can see the following example:
let arr = [
'Javascript',
'PHP',
'Mysql',
'Sql'
]
let str = arr.join('~').toLowerCase()
let newArr = str.split('~')
console.log(newArr) //Output: ["javascript", "php", "mysql", "sql"]
In this example, we have used Javascript join() method the mixed-case array into a string, after that use toLowerCase() to convert the string into lowercase. And Javascript split() the string back into an array.
In case, you pass the undefined string into toLowerCase() method and then you will get some error. The error looks like this: TypeError: Cannot read property ‘toLowerCase’ of undefined.
The following example:
let str = undefined
let res = str.toLowerCase();
console.log(res) // TypeError: Cannot read property ‘toLowerCase’ of undefined.
☞ Learn Vue.js from scratch 2018
☞ Learn JavaScript - Become a Zero to Hero
☞ JavaScript Programming Tutorial Full Course for Beginners
☞ Vue js Tutorial Zero to Hero || Brief Overview about Vue.js || Learn VueJS 2023 || JS Framework