Sorry, I am new to javascript and i'm just trying to get my feet wet.
I have used join()in the past without problems, but for some reason this join seems to return a blank string.
The information in myArray seems to be formatted correctly.
any help would be much appreciated. Thanks!
function titleCase(str) {
var splitArray = str.split(" ");
var myArray = [];
var joinArray = myArray.join(' ');
for (var i in splitArray) {
myArray.push(splitArray[i].charAt(0).toUpperCase() + splitArray[i].slice(1).toLowerCase());
}
return joinArray;
}
titleCase("capitalize the first letter of each word in this string");
joinArray, which is created at a timemyArrayis empty. You can assign a joined array after the loop, or just returnmyArray.join(' ').