Remove duplicates from string keeping the order according to last occurrences | 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 removeDuplicates ( str ) { let n = str . length ; let res = " " ; for ( let i = 0 ; i < n ; i ++ ) { let j ; for ( j = i + 1 ; j < n ; j ++ ) if ( str [ i ] == str [ j ] ) break ; if ( j == n ) res = res + str [ i ] ; } return res ; } let str = " " ; document . write ( removeDuplicates ( str ) ) ;