The toLowerCase() method is part of the string object and has full support in all browsers.
- mystring is the text you wish to convert to lower case and can be any string variable
- The original variable is not modified, so the result of calling toLowerCase() will need to be assigned to a new variable or used immediately
- Your text will be returned with all characters converted to lower case
- You can do the opposite with the toUpperCase() method – converting all characters to UPPERCASE
To use toLowerCase(), simply call it from your existing string variable, assigning the result to a new variable:
var mystring = "Not the BEES!"; var result = mystring.toLowerCase(); console.log(result); // "not the bees!"
Converting a string’s case is frequently used when checking whether an email address or username is already in use in an authentication system or comparing values in arrays. It’s also useful when formatting other user input for storage in a database.