How to Lowercase the First Letter of a String in JavaScript
Published: Thursday, May 12, 2022
Greetings, friends! Here is a simple approach for converting the first letter of a string to lowercase using JavaScript.
javascript
const str = 'PineapplePizza';
console.log(str.charAt(0).toLowerCase() + str.slice(1));
// OUTPUT: pineapplePizza
In the code above, we can grab the first letter of a string by using the String.charAt method. We can then use String.toLowerCase method to lowercase the first letter.
The String.slice method retrieves part of a string, starting at a specified index. By passing in the value, 1, to this method, we are extracting the entire string except the first character.
Finally, we can use the string concatenation operator to create the final string!