Last updated on
"SHOUTING LOUDLY!".toLowercase(); // Returns "shouting loudly!"
There’s not much else to say regarding the toLowerCase method. It doesn’t take any parameters and can only be called on strings.
var message = "ARE YOU SURE?"; message = message.toLowerCase(); // message = "are you sure?"
There are few ways to do this. Probably what I would do is keep the first letter in the string and then call toLowerCase on every other letter in the string. This can be done with the slice() method.
var string = "HELLO TO YOU!"; var normalText = string.slice(0,1) + string.slice(1).toLowerCase(); // normalText = 'Hello to you!'
The first slice adds the uppercase ‘H’ to the normalText variable. The second slice adds the rest of the string but transforms it to lower case. This is assuming that the first letter of string is uppercase of course 🙂
You can also do something similiar using the toUpperCase() method too.
Don’t forget, it order to make the change permanent the toLowerCase method needs to assign it’s result to a variable.