How to Convert an Array to Uppercase in JavaScript

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

Here is a code example:

const originalArray = [ 'bmw', 'audi', 'mercedez', 'jaguar' ];

const upperCaseArray = originalArray.map(item => item.toUpperCase());

console.log(upperCaseArray);

Output

[ 'BMW', 'AUDI', 'MERCEDEZ', 'JAGUAR' ]

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

In the next step, we used the “map()” method to iterate through each array element and applied the “toUpperCase()” method to convert each string to uppercase. The result is a new array called uppercaseArray containing the uppercase versions of the original strings.

We used an arrow function to simplify the callback function passed to the “map()” method.