first letter capitalized code example

Example 1: first letter tuUppercase

const string = "tHIS STRING'S CAPITALISATION WILL BE FIXED."
const string = string[0].toUpperCase() + string.slice(1)

Example 2: make first letter uppercase

const publication = "freeCodeCamp";
publication[0].toUpperCase() + publication.substring(1);

Example 3: capitalize

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(" ");
}