How to do you use the string
toLowerCase() method in Node.js to transform a text string into all lowercase letters?
Luckily, Node.js has the built-in
String.toLowerCase() method, which converts a string to all lowercase letters in Node.js. It doesn't change anything else about the original string and doesn't take any parameters.
In this article, we'll give you a quick rundown on how to use it!
Here's a code example of it in action:
const yourString = "Dogs are better than cats." yourString.toLowerCase() // output: "dogs are better than cats."
As you can see, the
toLowerCase() method returns the value of the string but in all lowercase.
Here's another example, but with an original string that has all capital letters:
const yourString = "DOGS ARE BETTER THAN CATS." yourString.toLowerCase() // output: "dogs are better than cats."
And you should see that it works the same as the first code example did, regardless of how many uppercase letters were in the string or where they were located.
Thanks for reading and happy coding!