函数titleCase(str){ var strSplit=(str.split(“”)); var newLetter=[]; var returnString; var firstLetter; var restLetter; 对于(i=0;i<=(strSplit.length-1); i++){ firstLetter=strSplit[i].charAt(0).toUpperCase(); 对于(i=0;i<=(strSplit.length-1); i++){ firstLetter=strSplit[i].charAt(0).toUpperCase(); restLetter=strSplit[i].slice(1,str.Split); newLetter=firstLetter+restLetter; newLetter.join(“and”); } return newLetter; } } titleCase(“我是一个小茶壶”);
-
我找到了解决方案!! 这里是:-function titleCase(str){var strSplit=(str.split(''));var newLetter=[];var returnString;var firstLetter;var restLetter,for(i=0;i<strSplit.length;i++){firstLeter=strSplit[i].charAt(0).toUpperCase() ; newLetter.push(firstLetter+restLetter)// newLetter.join(“”);} return newLetter.join(“”)// return newLetter;}// titleCase(“我是一个小茶壶”); – 用户9179227 评论 2018年1月22日2:26 -
函数titleCase(str){var strSplit=(str.split(''));var newLetter=[];var returnString;var firstLetter;var restLetter,用于(i=0;i<strSplit.length;i++){firstLeter=strSplit[i].charAt(0).toUpperCase();//console.log(firstLeter);restLeter=strSplit[i].slice(1,str.split).toLowerCase(; newLetter.push(firstLetter+restLetter)// newLetter.join(“”);} return newLetter.join(“”)// return newLetter;}// titleCase(“我是一个小茶壶”); – 用户9179227 评论 2018年1月22日2:27
2个答案
函数titleCase(str){ 返回str.split(“”) .map(word=>word.charAt(0).toUpperCase()+word.slice(1).toLowerCase( .join(“”) } log(titleCase(“我是一个小茶壶”);
函数titleCase(str){ var strSplit=(str.split(“”)); var newLetter=[]; var firstLetter; var restLetter; 对于(i=0;i<strSplit.length;i++){ firstLetter=strSplit[i].charAt(0).toUpperCase(); restLetter=strSplit[i].slice(1,str.Split).toLowerCase(); newLetter.push(firstLetter+restLetter); } return newLetter.join(“”); } titleCase(“我是一个小茶壶”);