Q:

Getting unmatched values from 2 arrays in JavaScript?

Suppose we have 2 Arrays say :
 A [] => 1 2 3 4 5

 B [] => 1 2 7 4 5 

is there any method in jQuery which will give the unmatched values of 2 arrays in this case :
 Result [] => 3 7

A:

hiya working demo here: http://jsfiddle.net/mbKfT/
good read http://api.jquery.com/jQuery.inArray/
This uses inArray to check it the element is there if not add it to intersect array.
rest demo will sue out any doubts :)
code
var a1 = [1,2,3,4,5];
var a2 = [1,2,7,4,5];
var intersect = [];

$.each(a1, function(i, a1val) {

    if ($.inArray(a1val, a2) === -1) {   
        intersect.push(a1val);
    }
});

$.each(a2, function(i, a1val) {

    if ($.inArray(a1val, a1) === -1) {           
        intersect.push(a1val);
    }
});
$("div").text(intersect);
alert(intersect + " -- " + matches);

​

