-6

My first Json Array is like :

[
    {"Invent":"4","Beze":"256","mail":"abc@abc.com"},
    {"Invent":"4","Beze":"261","mail":"hg1@vrz.net"},
    {"Invent":"4","Beze":"260","mail":"hg2@vrz.net"},
    {"Invent":"4","Beze":"276","mail":"hg3@vrz.net"}
]

and second one is:

[
    {"Invent":"14","Beze":"259","mail":"abc1@abc.com"},
    {"Invent":"24","Beze":"264","mail":"hg4@vrz.net"},
    {"Invent":"34","Beze":"260","mail":"hg2@vrz.net"},
    {"Invent":"44","Beze":"276","mail":"hg7@vrz.net"}
]

i want to compare these array to find duplicate rows if 'Beze' value has duplicate entry...

Karan Singh
  • 876
  • 1
  • 6
  • 12
Vipin Saini
  • 39
  • 1
  • 2
  • 9
  • 9
    Seriously? You can't write a loop and comparison? Also, `mail` values need to be strings too. – evolutionxbox Apr 12 '17 at 11:53
  • So, if you get a duplicate then what would you do? – Jai Apr 12 '17 at 11:53
  • Sorry for my earlier comment. Please show your efforts using a [mcve], and try [doing some research beforehand](http://stackoverflow.com/questions/14930516/compare-two-javascript-arrays-and-remove-duplicates). – evolutionxbox Apr 12 '17 at 11:54
  • This might help: http://stackoverflow.com/questions/21987909/difference-between-two-array-of-objects-in-javascript – Rajesh Apr 12 '17 at 11:54

1 Answers1

0

Assumption:

1) you have to fill a third array with duplicate records.

2) There are no duplicates entries within each array

var arr1 = [
    {"Invent":"4","Beze":"256","mail":"abc@abc.com"},
    {"Invent":"4","Beze":"261","mail":"hg1@vrz.net"},
    {"Invent":"4","Beze":"260","mail":"hg2@vrz.net"},
    {"Invent":"4","Beze":"276","mail":"hg3@vrz.net"}
];

var arr2 = [
    {"Invent":"14","Beze":"259","mail":"abc1@abc.com"},
    {"Invent":"24","Beze":"264","mail":"hg4@vrz.net"},
    {"Invent":"34","Beze":"260","mail":"hg2@vrz.net"},
    {"Invent":"44","Beze":"276","mail":"hg7@vrz.net"}
];

var arr3 = [];

arr1.forEach(function(arr1Item) {
    arr2.forEach(function(arr2Item) {
        if (arr1Item.Beze === arr2Item.Beze)
            arr3.push(arr1Item);
    })
});

console.log(arr3);
Sachet Gupta
  • 822
  • 5
  • 18