text: String containing first letter of every word in a given string with spaces | Function to find string which has first character of each word . ; Traverse the string . ; If it is space , set v as true . ; Else check if v is true or not . If true , copy character in output string and set v as false . ; Driver code
code: function firstLetterWord ( str ) { let result = " " ; let v = true ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ' ' ) { v = true ; } else if ( str [ i ] != ' ' && v == true ) { result += ( str [ i ] ) ; v = false ; } } return result ; } let str = " " ; document . write ( firstLetterWord ( str ) ) ;