xxxxxxxxxx
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
xxxxxxxxxx
//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(); });
};
xxxxxxxxxx
const lower = 'this is an entirely lowercase string';
const upper = lower.charAt(0).toUpperCase() + lower.substring(1);
xxxxxxxxxx
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"
xxxxxxxxxx
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
// Example usage
const originalString = 'hello world';
const capitalizedString = capitalizeFirstLetter(originalString);
console.log(capitalizedString); // Output: "Hello world"
xxxxxxxxxx
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"
xxxxxxxxxx
const string = "tHIS STRING'S CAPITALISATION WILL BE FIXED."
const string = string.charAt(0).toUpperCase() + string.slice(1)
xxxxxxxxxx
function capitalizeFirstLetter(name) {
return name.replace(/^./, name[0].toUpperCase())
}
xxxxxxxxxx
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
xxxxxxxxxx
// this will only capitalize the first word
var name = prompt("What is your name");
firstLetterUpper = name.slice(0,1).toUpperCase();
alert("Hello " + firstLetterUpper + name.slice(1, name.length).toLowerCase());