Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
