You can make each word in a text start with a capital letter by using JavaScript. Here is an example of how you can achieve this:
function capitalizeWords(text) {
return text.replace(/w/g, function(char) {
return char.toUpperCase();
});
}
const text = "hello world";
const capitalizedText = capitalizeWords(text);
console.log(capitalizedText); // Output: Hello World
javascript复制成功复制代码
In this example, the capitalizeWords function uses a regular expression to target the first character of each word (indicated by w) and converts it to uppercase. This will capitalize the first letter of each word in the given text.