var stream = ["apple","orange", "grape", "peach","strawberry","watermelon", "kiwi", "raspberry"],
selection = ["apple", "peach","strawberry","kiwi", "raspberry"];
stream.forEach(function(elem) {
if( selection.indexOf(elem) > -1 ) {
// we have a match, do something.
}
});
Note that Array.prototype.forEachhelp and .indexOf()help are part of Javascript 1.6 and may not be supported by any InternetExplorer < version 9. See MDC's documentation on alternative versions.
There are lots of other ways to accomplish the same thing (using a "normal" for-loop for instance) but I figured this is probably the best trade-of in performans vs. readability.
Anyway, all the used Javascript 1.6 functions are actually very trivial to write on your own.
jQuerys $.inArray()help will also use Array.prototype.indexOf() if it's supported by the browser.