I am trying to split a sentence into individual words and create a new array. If the word is found in another array, I want to replace it with an empty string and add space where necessary.
The desired output should look like this:
Arr=["I want to eat", "","", and, "" ]
let str = "I want to eat Banana Apple and Mango";
var array1 = str.split(" ");
var array2 = ["Banana", "Apple","Mango", "hut", "gut"];
const res = array1.map((item) => array2.includes(item) ? "" : item);
console.log(res);