I have searched over the web can can\'t find anything to help me. I want to make the first letter of each word upper case within a variable.
So far i have tried:
Simplest way
let str="hiren raiyani"
str.toLowerCase().replace(/(?<= )[^\s]|^./g, a => a.toUpperCase());
user-defined function:
function capitalize(str){
return str.toLowerCase().replace(/(?<= )[^\s]|^./g, a => a.toUpperCase());
}
output: Hiren Raiyani
Use code as your user-defined function or direct