How do make the first letter of a string uppercase in JavaScript? How to capitalize the first letter of each word of a given string in JavaScript? JavaScript offers different ways to capitalize the first letter of each word of a given string. Let’s see the example for Capitalize the first letter of each word:- //CAPITALIZE THE FIRST LETTER OF EACH WORD OF A GIVEN STRING var capitalize = function ( string ) { if ( string !== undefined && string . length > 0 ) { var splitStr = string . split ( " " ); for ( var i = 0 ; i < splitStr . length ; i ++) { var j = splitStr [ i ]. charAt ( 0 ). toUpperCase (); splitStr [ i ] = j + splitStr [ i ]. substr ( 1 ). toLowerCase (); } return splitStr . join ...
Angular, React, JavaScript, Java, PHP, SQL, C#, Vue, NodeJs, TypeScript and Interview Questions Answers