![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove all characters of first string from second JavaScript
Let’s say, we have two strings that contains characters in no specific order. We are required to write a function that takes in these two strings and returns a modified version of the second string in which all the characters that were present in the first string are omitted.
Following are our strings −
const first = "hello world"; const second = "hey there";
Following is our function to remove all characters of first string from second −
const removeAll = (first, second) => { const newArr = second.split("").filter(el => { return !first.includes(el); }); return newArr.join(""); };
Let's write the code for this function −
Example
const first = "hello world"; const second = "hey there"; const removeAll = (first, second) => { const newArr = second.split("").filter(el => { return !first.includes(el); }); return newArr.join(""); }; console.log(removeAll(first, second));
Output
The output in the console will be −
yt
Advertisements