Master toLowercase JavaScript: Your Ultimate Guide for 2023!

November 16, 2023
Master toLowercase JavaScript: Your Ultimate Guide for 2023!
Table of Contents
  • toLowerCase()
  • Using toLowerCase() with Arrays
  • Case Insensitive Search
  • Browser Compatibility

In JavaScript, manipulating strings is a common task. One such manipulation is converting a string to lowercase using toLowerCase() method. This method does not affect any of the special characters, digits, and the alphabets already in lowercase.

1var str = "Hello World!";
2var res = str.toLowerCase(); // returns "hello world!"

toLowerCase()

The toLowerCase() method in JavaScript converts all the uppercase characters in a string to lowercase characters and returns the result. It does not change the original string.

1var text = "JavaScript Tutorial";
2var result = text.toLowerCase(); // returns "javascript tutorial"

Using toLowerCase() with Arrays

You can also use toLowerCase() with arrays. This is particularly useful when you want to normalize data for comparison.

1var array = ["JavaScript", "HTML", "CSS"];
2var lowerCaseArray = array.map(item => item.toLowerCase());
3console.log(lowerCaseArray); // returns ["javascript", "html", "css"]

toLowerCase() is very useful for case insensitive search. By converting both the source and target strings to lowercase, you can ensure that the search is case insensitive.

1var text = "Learn JavaScript";
2var searchTerm = "JAVASCRIPT";
3if (text.toLowerCase().indexOf(searchTerm.toLowerCase()) > -1) {
4 console.log("Found");
5} else {
6 console.log("Not Found");
7} // Will log `Found`

Browser Compatibility

The toLowerCase() method is compatible with all modern browsers, and IE6 and up. If you found this post useful, you might also like our JavaScript Course.

For more in-depth understanding, you can refer to MDN's documentation on toLowerCase().

Related courses

1 Course

Javascript Fundamentals Course

Javascript Fundamentals

4.7+
834 reviews

Stay Ahead with Code highlights

Join our community of forward-thinkers and innovators. Subscribe to get the latest updates on courses, exclusive insights, and tips from industry experts directly to your inbox.

3D Letter

Related articles

114 Articles

Start learning for free

If you've made it this far, you must be at least a little curious. Sign up and grow your programming skills with Code Highlights.

Start learning for free like this happy man with Code Highlights