text: String containing first letter of every word in a given string with spaces | Javascript implementation of the above approach ; we are splitting the input based on spaces ( s ) + : this regular expression will handle scenarios where we have words separated by multiple spaces ; charAt ( 0 ) will pick only the first character from the string and append to buffer ; Driver code
code: var charBuffer = " " ; function processWords ( input ) { var s = input . split ( ' ' ) ; s . forEach ( element => { charBuffer += element [ 0 ] ; } ) ; return charBuffer ; } var input = " " ; document . write ( processWords ( input ) ) ;