fcc:使一句话中的每个单词的首字母大写(slice、首字母大写+剩余字母)

版权声明:内容多为自言自语,请自行判断有无价值。 https://blog.csdn.net/weixin_41702247/article/details/81486709
function titleCase(str) {
  var newStr=str.toLowerCase().split(' ').map(function(item){
    return item[0].toString().toUpperCase()+item.slice(1);
  }).join(' ');
  return newStr;
}
titleCase("I'm a little tea pot");

猜你喜欢

转载自blog.csdn.net/weixin_41702247/article/details/81486709