I have a target array ["apple","banana","orange"], and I want to check if other arrays contain any one of the target array elements.
For example:
["apple","grape"] //returns true;
["apple","banana","pineapple"] //returns true;
["grape", "pineapple"] //returns false;
How can I do it in JavaScript?
forloop and iterate over the target array. If every element is contained within the current array (usecurrent.indexOf(elem) !== -1), then they're all in there.trueorfalsethen you need to use.filter():: Javascript algorithm to find elements in array that are not in another array