xxxxxxxxxx
const Capitalize = function(string){
return string[0].toUpperCase + string.slice(1).toLowerCase;
}
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
export const toCapitalize = (str) => {
return str.charAt(0).toUpperCase() + str.slice(1);
};
xxxxxxxxxx
const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1)
capitalize("follow for more")
// Result: Follow for more
xxxxxxxxxx
const toCapitalCase = (string) => {
return string.charAt(0).toUpperCase() + string.slice(1);
};
xxxxxxxxxx
const capitalizeFirstLetter(string) =>
string.charAt(0).toUpperCase() + string.slice(1).toLowerCase()
xxxxxxxxxx
function capitalizeName(name) {
return name.replace(/\b(\w)/g, s => s.toUpperCase());
}
xxxxxxxxxx
const capitalize = s => s && s[0].toUpperCase() + s.slice(1)
// to always return type string event when s may be falsy other than empty-string
const capitalize = s => (s && s[0].toUpperCase() + s.slice(1)) || ""
xxxxxxxxxx
const str = 'flexiple';
const str2 = str.charAt(0).toUpperCase() + str.slice(1);
console.log(str2);
//Output: Flexiple
const str = 'abc efg';
const str2 = str.charAt(0).toUpperCase() + str.slice(1);
console.log(str2);
//Output: Abc efg
xxxxxxxxxx
myString = 'the quick green alligator...';
myString.replace(/^\w/, (c) => c.toUpperCase());
myString = ' the quick green alligator...';
myString.trim().replace(/^\w/, (c) => c.toUpperCase());