When you work with strings in any programming language, you'll often need to change the case of the string.
That can be either turning the entire string to uppercase or lowercase.
Converting a string to uppercase is very simple.
Just use the built-in
toUpperCase() method on the string that you want to transform.
The method will return a new string with all of the characters in the original string in uppercase.
Let's first start with a sample string:
const string = "This is a string."; const uppercasedString = string.toUpperCase(); console.log(uppercasedString);
THIS IS A STRING.
You can similarly do the reverse and lowercase strings by using the
This method will take a string and convert all uppercase characters to lowercase and return the new string.
const string = "THIS IS A STRING."; const lowercasedString = string.toLowerCase(); console.log(lowercasedString);
this is a string.
Simply make use of the built-in
toLowerCase() methods on strings.
Thanks for reading and happy coding!
Leave us a message!