![]() Similar to the toLowerCase() method, the toLocaleLowerCase() method does not change the original value of the string as well. This is because these languages conflict with the regular Unicode case mappings, so you might get differing outputs in these cases. This shouldn’t affect your output at all, except for in certain languages like Turkish. It looks at the language setting of the browser and spits out an output based on that. This is also a predefined Javascript method, and it works similar to the toLowerCase() method, the only difference being this method converts a given string to lowercase based on the user’s current locale that is, the locale of the browser on which the program is run. You can also use the toLocaleLowerCase() method to convert an entire string to lowercase, that is, to convert all of its characters to lowercase. If you want to affect the original value of the string, then you’ll have to assign the lowercase version back to the original string. Now, the string “b” will hold the lowercase version of the string “a”. Let’s look at the output we get:Īs you can see, the original string remains the same.īut you can assign the new lowercase string to another variable, if that’s what you want to do. So, we’ve displayed 2 strings, the lowercase version, and then the original version, after the toLowerCase() method was applied on it. If you noticed in the previous example, the value of the string “a” will remain the same, even though we applied the toLowerCase() function on it. I also want to point out the fact that this function does not change the original value of the string. So, while using this function, make sure that you’re using uppercase for the required letters. ![]() Javascript is a case sensitive language, even more so for its predefined function. Things to note about this functionīefore we move on to the next section, I want to point out a few things to you.ĭid you notice the capital letters in the toLowerCase() method? Both “L” and “C” are in uppercase. So, that’s how you can use Javascript’s built-in toLowerCase() method to convert a given string completely to lowercase. There was no change in the string at all because this function only works on uppercase letters. If I apply this new string to the function, I’ll get the following output: What if a string has no uppercase letters at all? What would the output be in that case? Let’s see. If I display this string with the toLowerCase() function, I’ll get the following output.Įvery letter was converted to lower case. Let’s look at another example where every letter is uppercase. So, this function goes through the entire string and makes every letter lowercase. Notice how the “H” in “Hello” and “W” in “World” are now in lowercase. The above lines of code will produce the following output: Then, I’ll use the toLowerCase() method to display the lowercase version of the string. I’ll declare a variable “a” and assign it a string “Hello World”. Let’s look at an example of how to do implement this function. ![]() The above syntax will produce a lowercase version of the given string. The syntax is as follows: string.toLowerCase() One of the easiest ways to convert a string to lowercase is by using Javascript’s toLowerCase() method. ![]() This means we’ll be converting the first letter in a sentence to lowercase as well. There are multiple ways of doing the same, one of the easiest is to convert every character into lowercase, regardless of where it is. In this tutorial, let’s look at different ways of converting a given string to lowercase.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |