To find the characters in the first string that are not present in the second string in JavaScript, you can use array methods like filter and includes.
In this example,
str1
and str2
with different values.split
method.str1
array that are not included in str2
array using the filter
method combined with includes
method.// Find Characters Not Present in Second String
const str1 = 'Hello World';
const str2 = 'apple';
const diff = str1.split('').filter(char => !str2.includes(char)).join('');
console.log('Characters not present in second string:', diff);
Characters not present in second string: Ho Word
In this tutorial, we learned How to find the Characters in the First String that are not Present in the Second String in JavaScript language with well detailed examples.