Title Case a Sentence_toUpperCase loop [SOLVED]

I realize that my approach isn’t elegant, and is clunky. I’m seperating each word into an array then just taking the capitalization of the first letter of each array. then finally combining them later on to be returned.
my question is for the line where i’m trying to upercase the first letter. It only outputs the first letter, and won’t loop through the whole array arr.
Also it looks like when I create teh array and add each letter if it isn’t a " " (space), the array has to be an empy string or else it will append to undefined how do I workaround if I don’t know how long the incoming string will be?

function titleCase(str) {
  var arr=["","","","",""];
  var cc=0;
  for(i=0;i<str.length; i++){
    //if its a space increment the coutner fo the arr[aarray counter]
    //otherwise itterage trhough str and push each letter into sepperate array.str[i].push()
   // document.write(str[i])
    if(str[i]==" "){
   //then we once its all split up we can capitalize each first letter after that combine them all togheter to make one sentence to return
  return ;

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

I was trying to change the capitalization while I was in the first loop. Once I split string, get out of that loop and itterate to capitalize it comes out correctly

Also was able to look over other peoples answers I guess my apporach is pretty similar.