I am trying to capitalize the first letter of only the first word in a sentence.
This is the data in the tsx file { this.text({ id: downloadPriceHistory
You only need to capitalize the first letter and concatenate that to the rest of the string converted to lowercase.
function titleCase(string){
return string[0].toUpperCase() + string.slice(1).toLowerCase();
}
console.log(titleCase('Download Price History'));
This can also be accomplished with CSS by setting text-transform
to lowercase
for the entire element and using the ::first-letter
pseudo element to set the text-transform
to uppercase
.
.capitalize-first {
text-transform: lowercase;
}
.capitalize-first::first-letter {
text-transform: uppercase;
}
Download Price History