1

There are two different objects in single array, i have to compare these array if the values are different then i have to get the Array1 value

Array1.push({
    "Name": "Max",
    "Occupation": "Agri",
    "Location": "KGP" 
});

Array2.push({
    "Name": "Alex",
    "Occupation": "S.E",
    "Location": "Mut" 
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Andy
  • 35
  • 8

1 Answers1

1

You can compare Like below:

var array1 = [1, 2, 3, 4, 5, 6];
var array2 = [1, 2, 3, 4, 5, 6, 7, 8, 9];
var foo = [];
var i = 0;
jQuery.grep(array2, function(el) {

    if (jQuery.inArray(el, array1) == -1) foo.push(el);


    i++;

});


alert(" the difference is " + foo);
Raghbendra Nayak
  • 1,606
  • 3
  • 22
  • 47
  • sorry , it works for the above given code, but for my code it doesn't works – Andy Sep 21 '16 at 11:45
  • There are lot of answer available for same, so it would be better if you share your complete code then we can help more. – Raghbendra Nayak Sep 21 '16 at 11:47
  • Array1.push({ "Name": "Max", "Occupation": "Agri", "Location": "KGP" }); Array2.push({ "Name": "Alex", "Occupation": "S.E", "Location": "KGP" }); in the above arrays i have different values in properties Name and Occupation but the location have the same value as that of Array1, – Andy Sep 21 '16 at 11:50
  • here i want to get Name and Occupation properties (which is different) – Andy Sep 21 '16 at 11:51
  • we have to compare the two arrays and here i want to get Name and Occupation properties (which is different) – Andy Sep 21 '16 at 11:54