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
, defaultMessage: 'Download Price History' }) }
the id shown above comes from the database where it could be send to the api in various forms.
I have tried to use this logic below:
export function titleCase(string) {
string = 'hello World';
const sentence = string.toLowerCase().split('');
for (let i = 0; i < sentence.length; i++) {
sentence[i] = sentence[i][0].toUpperCase() + sentence[i];
}
return sentence;
}
For example, for the input "Download Price History"
, the result should be "Download price history"
.