Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Web Technology by (47.6k points)

How do I make the first letter of a string uppercase, but not change the case of any of the other letters?

For example:

"this is a test" -> "This is a test"

"the Eiffel Tower" -> "The Eiffel Tower"

"/index.html" -> "/index.html"

1 Answer

0 votes
by (106k points)

For making the first letter of a string uppercase in JavaScript you can use String.charAt()and in the argument of the function, you will pass an index of the string that you want to make capital. Below is the code for the same:-

function capitalizeFirstLetter(string) { 

return string.charAt(0).toUpperCase() + string.slice(1); 


Related questions

Browse Categories