If you do this kind of thing regularly, you may be interested in a Set object that makes this kind of stuff pretty easy:
var array1 = [1, 2, 3, 4, 5, 6];
var array2 = [1, 2, 3, 4, 5, 6, 7, 8, 9];
var common = new Set(array1).intersection(array2).keys();
The open source Set object (one simple source file) is here: https://github.com/jfriend00/Javascript-Set/blob/master/set.js
Along with the intersection()
method used here, it has all sorts of other set operations (union, difference, subset, superset, add, remove ...).
Working demo: http://jsfiddle.net/jfriend00/5SCdD/