two array difference using jquery grep function

by Francis 2013-08-20 13:09:05

Two array difference using jquery grep function
It is use to find difference between array1 and array2.

var array1 = [4, 5, 6];
var array2 = [4, 5, 6, 7, 8, 9, 10];
var difference = [];

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

Result :
Difference : 7, 8, 9, 10
938
like
0
dislike
0
mail
flag

You must LOGIN to add comments