Well, since you specified jQuery, try the following:
var arr1 = [2, 3, 4];
var arr2 = [1, 2, 3];
var arr3 = $.merge($.grep(arr1, function(el, idx) {
return $.inArray(el, arr2) > -1;
}, true), $.grep(arr2, function(el, idx) {
return $.inArray(el, arr1) > -1;
}, true));
alert(arr3);
It is probably not very effective, but it is relatively short.
source
share