📜  word javascript代码示例中的大写

📅  最后修改于: 2022-03-11 15:03:39.637000             🧑  作者: Mango

代码示例4
//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(); });
};