Syntax
The syntax for Javascript’s toLowercase() function is as follows:
The toLowerCase() function converts all the alphabets in a string into lower-case letters. This function does not change the original value of the variable. Instead, the function creates a new string for the instance. In this way, the function does not take any arguments, although the parentheses “()” are used for taking arguments. But, with the toLowercase() function, you follow the same conventions of a function.
Let us now look at some examples.
Examples
Suppose there is a string that includes some uppercase and lowercase letters, such as the following string:
But, we need to convert the string entirely into lower-case letters. So, we will simply apply the following:
As you can see, the string has been converted to a formatted string. All the letters are now in lower-case format. It is as simple as that.
This function is for the string. But, this is not only restricted/limited here. We can apply the function to an array of strings and even to an array of objects containing strings, as well.
Let us take a look:
First, we will write down the array of strings, as follows:
Now, to change the term “GREAT” to all lowercase letters, we will apply the following:
where ‘2’ is the index of “GREAT”.
As you can see, now, the term “GREAT” has been converted into lower-case letters. We did something similar for two other strings: [0] for the term “Hi” and [1] for the term “LinuxHint.”
Let us now see how we can apply this function to an array of objects in which the objects contain the string, as follows:
To convert the term “BOB” to all lower-case letters, we will change it as follows:
Awesome. As you can see, we can do a lot with Javascript’s toLowerCase() function.
Conclusion
In this article, we showed you how to convert string characters to lower-case. We also showed you how to apply the same function to an array of strings and an array of objects containing strings. I hope that this article proved beneficial for converting an informal string into a cleaner and more formal-looking lowercase string. You can learn more about Javascript at linuxhint.com.
from Linux Hint https://ift.tt/3570VGt
0 Comments