Skip to main content

Posts

Showing posts with the label capitalize the first letter of each word of a given string in JavaScript

Capitalize the first letter of each word of a given string in JavaScript

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