How to Convert an Array to Lowercase in JavaScript

Here are two ways to convert an array to lowercase in JavaScript:

  1. Using toLowerCase() and map() methods
  2. Using an iteration

Method 1: Using the toLowerCase() with map()

The easiest way to convert all elements of an array to lowercase is to iterate over the array and call “.toLowerCase()” on each element using the “map()” method.

const originalArray = ['BMW', 'AUDI', 'MERCEDEZ', 'JAGUAR'];

const lowercaseArray = originalArray.map(item => item.toLowerCase());

console.log(lowercaseArray);

Output

[ 'bmw', 'audi', 'mercedez', 'jaguar' ]

In this code, we have an array called originalArray that contains strings in uppercase.

In the next step, we used the “map()” method to iterate through each array element and applied the “toLowerCase()” method to convert each string to lowercase.

The result is a new array called lowercaseArray containing the lowercase versions of the original strings.

We used an “arrow function” to simplify the callback function passed to the “map()” method. The result is the same as in the previous example.

Using an iteration

If you have an array of strings and you want to convert each string to lowercase, you can use a loop to iterate over each element, convert it to lowercase using the .toLowerCase() method (assuming this is in JavaScript), and then add the result to a new array.

let originalArray = ['BMW', 'AUDI', 'MERCEDEZ', 'JAGUAR'];
let lowercasedArray = [];

for (let i = 0; i < originalArray.length; i++) {
  lowercasedArray.push(originalArray[i].toLowerCase());
}

console.log(lowercasedArray);

Output

['bmw', 'audi', 'mercedez', 'jaguar']