Css way : Use css property Text-transform with values as capitalize

Text-transform : capitalize;

JS way : 1. Make first character of string as capital 2. Loop over the given characters of string 3. Whenever we find a space i.e " " while looping over the string, We have to capitalize the next letter of string using toUpperCase() method.

function capitalizeStr(str){
 let arr = str.split("");
 arr[0] = arr[0].toUpperCase();
 for(let i in arr){
    if(arr[i-1] === " "){
        arr[i] = arr[i].toUpperCase();
 return arr.join('');
console.log(capitalizeStr('just to test')) //output: Just To Test