I want to remove some elements from the array containing the word Evil (filterString).
let guests = ["Partner", "Evil Nice Relative 1", "Nice Relative 2", "Evil One", "another evil", "another one", "another evil is here", "strange Evil is here", "someone Nicer", "Ugly Evil Bad"];
const filteredArray = [];
const filterString = "Evil";
function checkEvil() {
guests.filter((element, index) => {
if (element.toLowerCase().indexOf(filterString.toLowerCase()) !== -1) {
console.log(index);
guests.splice(index,1);
} else {
filteredArray.push(element);
}
});
console.log(guests);
}
Here is what I get for the original array (guests):
['Partner', 'Nice Relative 2', 'another evil', 'another one', 'strange Evil is here', 'someone Nicer']
Just want the guests array updated once the desired string (Evil) is filtered.