Program to replace every space in a string with hyphen | JavaScript program for the above approach ; Split by space and converting String to list and ; joining the list and storing in string ; returning the string ; Driver code
function printHyphen ( string ) { var lis = string . split ( " " ) string = lis . join ( " " ) ; return string ; } var string = " " ; document . write ( printHyphen ( string ) ) ;