How to use 'tocapitalize javascript' in JavaScript

Every line of 'tocapitalize javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
145function capitalize(string) {
146 return string.replace(/^[a-z]/, function(str) {
147 return str.toUpperCase();
148 });

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

7capitalize(str) {
8 if (!str) {
9 return str;
10 }
11 return str.replace(/^(.)/, c => c.toUpperCase());

Related snippets