
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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
- Related Articles
- JavaScript - Remove first n characters from string
- JavaScript Remove non-duplicate characters from string
- Check whether second string can be formed from characters of first string in Python
- Write a Regular Expression to remove all special characters from a JavaScript String?
- Remove all whitespaces from string - JavaScript
- Removing first k characters from string in JavaScript
- Remove first two characters of all fields in MySQL?
- Remove characters from a string contained in another string with JavaScript?
- How to remove all non-alphanumeric characters from a string in MySQL?
- Dynamic Programming: Is second string subsequence of first JavaScript
- Remove all non-alphabetical characters of a String in Java?
- Removing all non-alphabetic characters from a string in JavaScript
- Is the second string a rotated version of the first string JavaScript
- How to remove all special characters, punctuation and spaces from a string in Python?
- C# Program to remove duplicate characters from String

Advertisements