JavaScript String toLowerCase() Method

JavaScript String toLowerCase() function is “used to convert a string to lowercase letters and returns a new string with all characters”. It does not change the original string.

The toLowerCase() method raises TypeError when called on null or undefined.

Syntax

string.toLowerCase()

Parameters

It does not take any arguments.

Return Value

The toLowerCase() method returns the string value converted to lowercase and does not affect the value of the string itself.

Example 1: How to toLowerCase() function in JavaScript

Let’s define a string using single quotes and convert it into lowercase.

let strA = 'Avengers will be a great movie';

console.log(strA.toLocaleLowerCase());

Output

Javascript String toLowerCase Example

This is how you can convert Strings to lowercase.

Example 2: Converting all characters to lowercase

console.log('AppDividend'.toLocaleLowerCase());

console.log('KrunalLathiya'.toLowerCase());

Output

String.prototype.toLowerCase() Tutorial

Example 3: Converting all elements of the array to lowercase

To convert an array of elements to lowercase in Javascript, use the combination of join(), toLowerCase(), and split() methods.

let arr = [
  'MILLIE',
  'NOAH',
  'FINN',
  'SADIE'
]

let str = arr.join('~').toLowerCase()
let finArr = str.split('~')
console.log(finArr)

Output

[ 'millie', 'noah', 'finn', 'sadie' ] 

In the above code, we have used the join() method, the mixed-case array into a string, lowercase it, then split() the string back into an array.

Browser compatibility

  1. Chrome version 1 and above
  2. Edge version 12 and above
  3. Firefox version 1 and above
  4. Internet Explorer version 3 and above
  5. Opera version 3 and above
  6. Safari version 1 and above

Recommended Posts

JavaScript toUpperCase()

JavaScript toLocaleUpperCase()

JavaScript toLocaleLowerCase()

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.