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
//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
function capFirst(str) {
return str[0].toUpperCase() + str.slice(1);
}
console.log(capFirst('hello'));
//output
//Hello
xxxxxxxxxx
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
console.log(capitalizeFirstLetter('foo')); // Foo
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
let name = 'john';
name = name.charAt(0).toUpperCase() + name.slice(1); //slice(index) return string from index to index
console.log(name); // John
xxxxxxxxxx
function capitalizeFirstLetter(name) {
return name.replace(/^./, name[0].toUpperCase())
}
xxxxxxxxxx
const lower = 'this is an entirely lowercase string';
const upper = lower.charAt(0).toUpperCase() + lower.substring(1);