Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

jquery compare two arrays return difference

var array1 = [1, 2, 3, 4, 5, 6];
var array2 = [1, 2, 3, 4, 5, 6, 7, 8, 9];
var difference = [];

jQuery.grep(array2, function(el) {
        if (jQuery.inArray(el, array1) == -1) difference.push(el);
});

alert(" the difference is " + difference);​ // Changed variable name
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #jquery #compare #arrays #return #difference
ADD COMMENT
Topic
Name
3+2 =