Title Case A String

Why cant we do uppercase with following code… I tried a lot but the error is showing ‘0 is read-only’ . if i try to log each element there is no problem with that…so why cant we mutate it with following code

function titleCase(str) {
  var arr = str.split(' ');
  for (var i in arr){
    arr[i][0] = arr[i][0].toLocaleUpperCase();
    //or arr[i][0] = arr[i][0].toUpperCase();
  let neww = arr.join(' ');

titleCase("I'm a little tea pot");

Remember that strings are immutable.

This will show you the output as you are creating the new string and storing it in neww using the arr array. Secondly, only the first letter of word are getting stored in arr. You need to concatenate the rest of the letters of the word as follows:
arr[i] = arr[i][0].toUpperCase() + arr[i].slice(1);

Hope that helps