xxxxxxxxxx
function capitalizeWords(string) {
return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};
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 capitalize = str => str.charAt(0).toUpperCase() + str.slice(1)
capitalize("follow for more")
// Result: Follow for more
xxxxxxxxxx
//Updated
//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 capitalizeName(name) {
return name.replace(/\b(\w)/g, s => s.toUpperCase());
}
xxxxxxxxxx
const capitalizeFirstLetter(string) =>
string.charAt(0).toUpperCase() + string.slice(1).toLowerCase()
xxxxxxxxxx
const Capitalize = function(string){
return string[0].toUpperCase + string.slice(1).toLowerCase;
}
xxxxxxxxxx
myString = 'the quick green alligator...';
myString.replace(/^\w/, (c) => c.toUpperCase());
myString = ' the quick green alligator...';
myString.trim().replace(/^\w/, (c) => c.toUpperCase());