Saturday, July 28, 2012

Array Difference in Jquery

Hi

Here is the snippet to find the difference between the two arrays in JQUERY.

var array1 = ["test1", "test2","test3", "test4"];
var array2 = ["test1", "test2","test3","test4", "test5", "test6"];

var _array = new Array();

_array = jQuery.grep(array2, function (item) {
     return jQuery.inArray(item, array1) < 0;
});