String. prototype. toLowerCase()
Returns a copy of the string converted to lowercase. Useful for comparisons and normalizing data.
- Returns
- A new string with the letters converted to lowercase.
- Changes the original
- No
Example
#const email = ' Anna.Parker@Example.COM '
console.log(email.trim().toLowerCase())
console.log('ÉCOLE'.toLowerCase())Definition and usage
#The toLowerCase() method returns a new string in which every uppercase letter is converted to lowercase. Characters that are not letters stay unchanged, and the original string remains as it was. The method takes no arguments.
It is the simplest way to normalize text before comparing or searching it. An email address typed as Anna@Example.com and anna@example.com is, in practice, the same address, so it is worth lowercasing it before saving or checking it.
Just like toUpperCase(), the method relies on universal Unicode rules. For languages with different rules, such as Turkish, there is toLocaleLowerCase(), which takes a language code.
Syntax
#string.toLowerCase()More examples
#const courses = ['JavaScript for beginners', 'Advanced React', 'Python for beginners']
const query = 'REACT'
const results = courses.filter((course) => course.toLowerCase().includes(query.toLowerCase()))
console.log(results)const title = 'Loops In JavaScript'
const slug = title.toLowerCase().replaceAll(' ', '-')
console.log(slug)Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Normalize data in one place, for example when saving an email address, instead of remembering to call
toLowerCase()at every comparison. - When accents and language rules also matter for the comparison,
localeCompare()is the better tool.
Related entries
#- String.prototype.toUpperCase()Returns a copy of the string converted to uppercase. Handles accented letters correctly.
- String.prototype.includes()Checks whether a string contains the given piece of text. Returns true or false, and is case-sensitive.
- String.prototype.trim()Removes whitespace from both ends of a string: spaces, tabs, and newline characters.
- String.prototype.localeCompare()Compares two strings according to language rules. Returns a negative number, zero, or a positive number, perfect for sorting.
Spotted a mistake or missing an example? Write to us.