📜  大写 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:01             🧑  作者: Mango

代码示例1
function capitalize1(str) {
  const arrOfWords = str.split(" ");
  const arrOfWordsCased = [];

  for (let i = 0; i < arrOfWords.length; i++) {
    const word = arrOfWords[i];
    arrOfWordsCased.push(word[0].toUpperCase() + word.slice(1).toLowerCase());
  }

  return arrOfWordsCased.join(" ");
}