Answers for "how to capitalise the first letter of each word in javascript"

98

js first letter uppercase

//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
7

capitalize first letter javascript

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

console.log(capitalizeFirstLetter('foo bar bag')); // Foo
Posted by: Guest on June-22-2020
3

javascript uppercase first character of each word

const uppercaseWords = str => str.replace(/^(.)|\s+(.)/g, c => c.toUpperCase());

// Example
uppercaseWords('hello world');      // 'Hello World'
Posted by: Guest on July-03-2020
0

capitalize first letter of string javascript

let val = '  this is test ';
val = val.trim();
val = val.charAt(0).toUpperCase() + val.slice(1);
console.log("Value => ", val);
Posted by: Guest on September-16-2021

Code answers related to "how to capitalise the first letter of each word in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language