I have converted the string into an array and want to replace every first word with a capital letter for that I am using the replace method but not working
function titleCase(str) {
let arr = str.toLowerCase().split(' ');
for (let i = 0; i < arr.length; i++) {
arr[i].replace(arr[i][0], arr[i][0].toUpperCase())
}
let a = arr.join(' ');
return a;
}
console.log(titleCase("I'm a little tea pot"));