lowercase or uppercase all strings in array javascript 1

lowercase or uppercase all strings in array javascript

const names = ['Ali', 'Atta', 'Alex', 'John'];

const lowercased = names.map(name => name.toLowerCase());

console.log(lowercased);
// ['ali', 'atta', 'alex', 'john']

const uppercased = names.map(name => name.toUpperCase());

console.log(uppercased);
// ['ALI', 'ATTA', 'ALEX', 'JOHN']

Here is what the above code is Doing:
1. We have an array of names.
2. We use the map method to create a new array with the same number of elements as the original array.
3. We use the arrow function to transform each element in the array.
4. We return the transformed element.
5. We assign the new array to a variable.

Similar Posts