Capitalize First Letter Of Each Word In A String - JavaScript
问题 What is wrong with this function? I am lost thanks for help. function titleCase(str) { var splitStr = str.toLowerCase().split(\' \'); for (var i = 0; i < splitStr.length; i++) { if (splitStr.length[i] < splitStr.length) { splitStr[i].charAt(0).toUpperCase(); } str = splitStr.join(\' \'); } return str; } titleCase(\"I\'m a little tea pot\"); 回答1: You are not assigning your changes to the array again, so all your efforts are in vain. Try this: function titleCase(str) { var splitStr = str