Skip to main content

Capitalize only first character of a string in JavaScript

I finally had to do it since I always-always end up Googling it and land on this amazing one liner.

So there goes our amazing snippet:

'test string'.replace(/^[a-z]/, (m) => m.toUpperCase());

It is glorious.

Profile picture

Andrei Glingeanu's notes and thoughts. You should follow him on Twitter, Instagram or contact via email. The stuff he loves to read can be found here on this site or on goodreads. Wanna vent or buy me a coffee?