How do I capitalize the first character of a string, but not change the case of any of the other letters?
- this is a test -> This is a test
- the Eiffel Tower -> The Eiffel Tower
- /index.html -> /index.html
If you’re interested in the performance of a few different methods posted:
Here are the fastest methods based on this jsperf test (ordered from fastest to slowest).
As you can see, the first two methods are essentially comparable in terms of performance, whereas altering the
String.prototype is by far the slowest in terms of performance.