
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript Remove non-duplicate characters from string
We are required to write a JavaScript function that takes in a string and returns a new string with all non-duplicate characters removed from it.
For example −
If the input string is −
"teeth_foot"
Then the output should be −
"teetoot"
Therefore, let's write the code for this function −
Example
const str = 'teeth_foot'; const removeNonDuplicate = str => { const strArray = str.split(""); const duplicateArray = strArray.filter(el => { return strArray.indexOf(el) !== strArray.lastIndexOf(el); }); return duplicateArray.join(""); }; console.log(removeNonDuplicate(str));
Output
The output in the console will be −
teetoot
- Related Questions & Answers
- C# Program to remove duplicate characters from String
- PHP program to remove non-alphanumeric characters from string
- JavaScript - Remove first n characters from string
- Program to remove duplicate characters from a given string in Python
- How to remove non-ASCII characters from strings
- How to remove all non-alphanumeric characters from a string in MySQL?
- Removing all non-alphabetic characters from a string in JavaScript
- How to remove non-word characters in JavaScript?
- Remove all characters of first string from second JavaScript
- Remove characters from a string contained in another string with JavaScript?
- Remove all non-alphabetical characters of a String in Java?
- Remove/ filter duplicate records from array - JavaScript?
- Find All Duplicate Characters from a String using Python
- Java program to delete duplicate characters from a given String
- How to Remove Characters from a String in Arduino?
Advertisements