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:
Personally, I would use the following function:
var arrayContains = function(array, toMatch) {
var arrayAsString = array.toString();
return (arrayAsString.indexOf(','+toMatch+',') >-1);
}
The "toString()" method will always use commas to separate the values. Will only really work with primitive types.