only first letter capital in javascript code example
Example 1: javascript capitalize words
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function capitalizeWords(string) {
return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};
Example 2: capitalize first letter javascript
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
console.log(capitalizeFirstLetter('foo bar bag'));
Example 3: captitalize js
function capitalize2(str) {
str = str.toLowerCase();
const arrOfWords = str.split(" ");
const arrOfWordsCased = [];
for (let i = 0; i < arrOfWords.length; i++) {
const char = arrOfWords[i].split("");
char[0] = char[0].toUpperCase();
res.push(char.join(""));
}
return arrOfWordsCased.join(" ");
}
Example 4: capitalize first letter in each word javascript
search function
<ion-input [(ngModel)]="keyword" (ngModelChange)="toTitleCase($event)" class="input-container" placeholder="Enter Input"></ion-input>
function capital_letter(str)
{
str = str.split(" ");
for (var i = 0, x = str.length; i < x; i++) {
str[i] = str[i][0].toUpperCase() + str[i].substr(1);
}
return str.join(" ");
}
console.log(capital_letter("Write a JavaScript program to capitalize the first letter of each word of a given string."));
Example 5: capitalize first carater js
p.capitalize {
text-transform: capitalize;
}