THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.
It is a short tutorial on how to convert a string to lowercase letters in javascript.
For example, if the input is “Welcome to Cloudhadoop” and Output is “welcome to cloudhadoop”.
There are multiple ways to convert to lower case strings.
String provides toLowerCase() function to convert to lowercase letters.
Syntax:
toLowerCase()
It returns a new string in lowercase letters.
Here is an example
const str = 'Welcome to Cloudhadoop';
const resultStr = str.toLowerCase();
console.log(resultStr); // welcome to cloudhadoop
This example is a custom implementation without using toLowercase
fromCharCode
.function stringToLowerCase(str) { var output = ‘';
for (var i = 0; i < str.length; i++) { var code = str.charCodeAt(i); if (code > 64 && code < 91) { output += String.fromCharCode(code + 32); } else { output += str.charAt(i); } } return output; }
## Difference between toLowerCase and toLocalLowerCase
`toLowerCase` and `toLocalLowerCase` return a string of lower case letters, But `toLocalLowerCase` takes locale language and convert string differently in lower case.
to
## Conclusion
Converting string in upper case or normal case to lower case is straightforward.
🧮 Tags
Recent posts
React Button toggle on off example How to detect production or development build at runtime in React Difference between Development and Production Builds in React ReactJS How to focus input element on render| useRef and useEffect example Reactjs Fix Must call a super constructor in derived class before accessing thisRelated posts