// array which holds all values
const namesArr = ["Lily", "Roy", "John", "Jessica"];
// array of values that needs to be deleted
const namesToDeleteArr = ["Roy", "John"];
// make a Set to hold values from namesToDeleteArr
const namesToDeleteSet = new Set(namesToDeleteArr);
// use filter() method
// to filter only those elements
// that need not to be deleted from the array
const newArr = namesArr.filter((name) => {
// return those elements not in the namesToDeleteSet
return !namesToDeleteSet.has(name);
});
console.log(newArr); // ["Lily", "Jessica"]