1//capitalize only the first letter of the string.
2function capitalizeFirstLetter(string) {
3 return string.charAt(0).toUpperCase() + string.slice(1);
4}
5//capitalize all words of a string.
6function capitalizeWords(string) {
7 return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
8};
1function capitalizeFirstLetter(string) {
2 return string.charAt(0).toUpperCase() + string.slice(1);
3}
4
5console.log(capitalizeFirstLetter('foo')); // Foo
1search function
2
3<ion-input [(ngModel)]="keyword" (ngModelChange)="toTitleCase($event)" class="input-container" placeholder="Enter Input"></ion-input>
4
5
6function capital_letter(str)
7{
8 str = str.split(" ");
9
10 for (var i = 0, x = str.length; i < x; i++) {
11 str[i] = str[i][0].toUpperCase() + str[i].substr(1);
12 }
13
14 return str.join(" ");
15}
16
17console.log(capital_letter("Write a JavaScript program to capitalize the first letter of each word of a given string."));
18
19
1String.prototype.capitalize = function() {
2 return this.charAt(0).toUpperCase() + this.slice(1);
3}
4