Answered by : code-grepper
//capitalize only the first letter of the string.
function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1);
}
//capitalize all words of a string.
function capitalizeWords(string) { return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};
Source : | Last Update : Mon, 29 Jul 19
Answered by : xerothermic-xenomorph-wa03p7gj567j
function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1);
}
console.log(capitalizeFirstLetter('foo')); // Foo
Source : https://stackoverflow.com/questions/1026069/how-do-i-make-the-first-letter-of-a-string-uppercase-in-javascript | Last Update : Mon, 07 Sep 20
Answered by : you
function capitalizeFirstLetter(str) { return str.charAt(0).toUpperCase() + str.slice(1);
}
// Example usage
const text = "hello world";
const capitalizedText = capitalizeFirstLetter(text);
console.log(capitalizedText); // Output: "Hello world"
Source : | Last Update : Tue, 19 Sep 23
Answered by : afzal-afzal
function capFirst(str) { return str[0].toUpperCase() + str.slice(1); }
console.log(capFirst('hello'));
//output
//Hello
Source : https://www.freecodecamp.org/news/javascript-tolowercase-how-to-convert-a-string-to-lowercase-and-uppercase-in-js/ | Last Update : Fri, 18 Nov 22
Answered by : combative-crayfish-xu4hmew3x5l9
function capitalizeFirstLetter(name) { return name.replace(/^./, name[0].toUpperCase())
}
Source : | Last Update : Wed, 28 Apr 21
Answered by : you
function capitalizeFirstLetter(str) { return str.charAt(0).toUpperCase() + str.slice(1);
}
// Example usage
const myString = "hello world";
const capitalizedString = capitalizeFirstLetter(myString);
console.log(capitalizedString); // Output: "Hello world"
Source : | Last Update : Tue, 19 Sep 23
Answered by : kazi-mahbubur-rahman
const lower = 'this is an entirely lowercase string';
const upper = lower.charAt(0).toUpperCase() + lower.substring(1);
Source : | Last Update : Wed, 27 Jul 22
Answered by : praise-owode
var name = prompt("What is your name");
firstLetterUpper = name.slice(0,1).toUpperCase();
alert("Hello " + firstLetterUpper + name.slice(1, name.length).toLowerCase());
Source : | Last Update : Mon, 17 Oct 22
Answered by : abdelhadi-belaid
//1 using OOP Approach
Object.defineProperty(String.prototype, 'capitalize', { value: function() { return this.charAt(0).toUpperCase()+ this.slice(1).toLowerCase(); }, enumerable: false
});
function titleCase(str) { return str.match(/\w\S*/gi).map(name => name.capitalize()).join(' ');
}
//-------------------------------------------------------------------
//2 using a simple Function
function titleCase(str) { return str.match(/\w\S*/gi).map(name => capitalize(name)).join(' ');
}
function capitalize(string) { return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
Source : | Last Update : Thu, 17 Feb 22
Answered by : grieving-gharial-54afdxs4rdwl
String.prototype.capitalize = function() { return this.charAt(0).toUpperCase() + this.slice(1);
}
Source : https://stackoverflow.com/questions/1026069/how-do-i-make-the-first-letter-of-a-string-uppercase-in-javascript | Last Update : Mon, 02 Aug 21