从第二 JavaScript 字符串中移除第一个字符串的所有字符
假设我们有两个字符串,其中包含的字符没有特定顺序。我们需要编写一个函数,该函数接收这两个字符串,并返回第二个字符串的修改版本,其中省略了所有存在于第一个字符串中的字符。
以下是我们的字符串 −
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("");
};为此函数编写代码 −
示例
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));输出
控制台中的输出将为 −
yt
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP