Answers for "how to capitalize first letter js"

98

javascript uppercase first letter

//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(); });
};
Posted by: Guest on July-22-2019
0

return first letter of string javascript in uppercase

function capitalizeFirstLetter(string) {
  return string.charAt(0).toUpperCase() + string.slice(1);
}

console.log(capitalizeFirstLetter('foo')); // Foo
Posted by: Guest on August-31-2020
0

capitalize first letter of each word javascript

const titleCase = function(text) {
  let newText = '';
  text = text.toLowerCase();
  text = text.charAt(0).toUpperCase() + text.slice(1);
  for (let i = 0; i < text.length; i++) {
    if (text[i] === ' ') {
      newText += ' ' + text[i+1].toUpperCase();
      i++;
    } else {
      newText += text[i];
    }
  }
  return newText;
}
Posted by: Guest on January-12-2021

Code answers related to "how to capitalize first letter js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language