JavaScript – Convert String to Lowercase

To convert a string to lowercase in JavaScript, call toLowerCase() method on the string. The expression returns a new string with all the characters of the calling string transformed to lowercase.

Syntax

The syntax to call toLowerCase() function on the string str is

</>
Copy
str.toLowerCase()

toLowerCase() returns a new string with the contents of the original string transformed to lowercase.

Examples

In the following example, we take a string str, convert this string to lowercase, and display both the original string, and lowercase transformed string in #output.

index.html

<!DOCTYPE html>
<html lang="en">
<body>
    <pre id="output"></pre>
    <script>
        var str = 'Hello World';
        var result = str.toLowerCase();
        var output = 'Original string  : ' + str;
        output += '\n\nLowercase string : ' + result;
        document.getElementById('output').innerHTML = output;
    </script>
</body>
</html>

Conclusion

In this JavaScript Tutorial, we learned how to transform a given string to lowercase in JavaScript, using toLowerCase() method, with examples.