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
145function capitalize(string) {
146 return string.replace(/^[a-z]/, function(str) {
147 return str.toUpperCase();
148 });
149}
7capitalize(str) {
8 if (!str) {
9 return str;
10 }
11 return str.replace(/^(.)/, c => c.toUpperCase());
12}

Related snippets