How to Convert an Array to Lowercase in JavaScript

To convert an array of strings to lowercase in JavaScript, you can use the “map()” method to iterate through each array element and call the “toLowerCase()” method on each string.

Example

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.

Leave a Comment