How to Convert first word of a sentence to UPPERCASE LETTERS in javascript/angularjs?

93 Views Asked by At

How to Convert first word of a sentence to UPPERCASE LETTERS in javascript/angularjs ?

2

There are 2 best solutions below

2
Abdul On

let firstUpper = "some text to work".split(' ')[0].toUpperCase();

0
GIbrain On

Basic solution:

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

   console.log(capitalizeFirstLetter('foo')); // Foo ´´´