Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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)
edited by

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); 

}

If you are passionate to pursue a career in Web Development, you can take up Web Development Online Courses by Intellipaat! 

Related questions

Browse Categories

...