I need to filter an array so that certain values don't get output if they contain a selection of words or phrases. For example, if my array goes something like ["John Smith", "Bob Smith", "John Doe", "Dave Jones"]
I might want to exclude values that contain Bob or Dave.
Currently, to do this I have the following:
const filtered =
names.filter(
myArray.toLowerCase().indexOf('bob') === -1
&& myArray.toLowerCase().indexOf('dave') === -1
);
let content = '';
filtered.forEach(item => {...}
This is great and it works, but If I was to increase the number of words to filter out this would become quite long-winded.
I thought I could get around this by using an array to filter by
myArray.toLowerCase().indexOf(['bob', 'dave']) === -1
This, as it turns out returns nothing at all. So went on to try
['bob', 'dave'].some(x => myArray.toLowerCase().indexOf(x) === -1)
but this also failed. I have an idea that the reason that these may be failing is that the logic is somehow looking for both values, but I've neither been able to prove that nor work out how to fix it.