10 examples of 'javascript capitalize all letters' in JavaScript

Every line of 'javascript capitalize all letters' 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 });
149}
Important

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

38export function capitalizeFirstLetter(string: string): string {
39 return string.charAt(0).toUpperCase() + string.slice(1);
40}
5function capitalizeFirstLetter(string) {
6 return string.charAt(0).toUpperCase() + string.slice(1)
7}
2function LetterCapitalize (str) {
3 // First, we use the split method to divide the input string into an array of individual words
4 // Note that we pass a string consisting of a single space into the method to "split" the string at each space
5 str = str.split(' ');
6
7 // Next, we loop through each item in our new array...
8 for (var i = 0; i < str.length; i++) {
9 // ...and set each word in the array to be equal to the first letter of the word (str[i][0]) capitalized using the toUpperCase method.
10 // along with a substring of the remainder of the word (passing only 1 arg into the substr method means that you start at that index and go until the end of the string)
11 str[i] = str[i][0].toUpperCase() + str[i].substr(1);
12 }
13 // Finally, we join our array back together...
14 str = str.join(' ');
15
16 // ...and return our answer.
17 return str;
18}
4function capitalizeString(string: string): string {
5 return string.charAt(0).toUpperCase() + string.slice(1)
6}
7export function capitalize (string) {
8 return string && (string.charAt(0).toUpperCase() + string.slice(1))
9}
22function _capitalize(string) {
23 return string && (string.charAt(0).toUpperCase() + string.slice(1));
24}
3function capitalize (string) {
4 return string.charAt(0).toUpperCase() + string.substr(1).toLowerCase()
5}
7function capitalize(str) {
8 return str && str[0].toUpperCase() + str.slice(1);
9}
3function capitalize(string) {
4 return string.charAt(0).toUpperCase() + string.slice(1);
5}

Related snippets