Remove duplicates from a given string | JavaScript program to remove duplicate character from character array and print in sorted order ; Used as index in the modified string ; Traverse through all characters ; Check if str [ i ] is present before it ; If not present , then add it to result . ; Driver code
function removeDuplicate ( str , n ) { var index = 0 ; for ( var i = 0 ; i < n ; i ++ ) { var j ; for ( j = 0 ; j < i ; j ++ ) { if ( str [ i ] == str [ j ] ) { break ; } } if ( j == i ) { str [ index ++ ] = str [ i ] ; } } return str . join ( " " ) . slice ( str , index ) ; } var str = " " . split ( " " ) ; var n = str . length ; document . write ( removeDuplicate ( str , n ) ) ;