capitalize first letter of string code example

Example 1: javascript capitalize words

//capitalize only the first letter of the string. 
function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}
//capitalize all words of a string. 
function capitalizeWords(string) {
    return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};

Example 2: javascript capitalize first letter

const lower = 'this is an entirely lowercase string';
const upper = lower.charAt(0).toUpperCase() + lower.substring(1);

Example 3: first letter tuUppercase

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

Example 4: how to capitalize first letter in python

# To capitalize the first letter in a word or each word in a sentence use .title()
name = tejas naik
print(name.title())    # output = Tejas Naik

Example 5: captitalize js

function capitalize2(str) {
  str = str.toLowerCase();

  const arrOfWords = str.split(" ");

  const arrOfWordsCased = [];

  for (let i = 0; i < arrOfWords.length; i++) {
    const char = arrOfWords[i].split("");
    char[0] = char[0].toUpperCase();

    res.push(char.join(""));
  }
  return arrOfWordsCased.join(" ");
}

Example 6: make first letter uppercase

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