I am trying to use the first letter in every word in a string. My code is as follows:
function LetterCapitalize(str)
{
var words=str.split(" ");
var newArray=[];
for(i=0; i<words.length; i++)
{
var aWord=words[i];
aWord[0]=aWord[0].toUpperCase();
newArray.push(aWord);
};
newArray.join(" ");
return newArray;
};
So, the problem that I see is that when I try to assign aWord [0] to its capital value, no assignment happens? How do I change this so that an appointment occurs?
PS. I know there is a regular expression method that can do this in one fell swoop, but I just picked up javascript a few days ago and haven't got it yet! as such, any advice that is not related to regular expression is greatly appreciated.
source
share