Remove the first and last occurrence of a given Character from a String |  ; Traverse the given String from the beginning ; If ch is found ; Traverse the given String from the end ; If ch is found ; Driver Code
Function to remove first and last occurrence of a given character from the given String * / function removeOcc ( s , ch ) { for ( var i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] === ch ) { s = s . substring ( 0 , i ) + s . substring ( i + 1 ) ; break ; } } for ( var i = s . length - 1 ; i > - 1 ; i -- ) { if ( s [ i ] === ch ) { s = s . substring ( 0 , i ) + s . substring ( i + 1 ) ; break ; } } return s ; } var s = " " ; var ch = " " ; document . write ( removeOcc ( s , ch ) ) ;