Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to compare two object of array and output mismatching values only?

I am trying to find the most efficient way to output an object of array having mismatching values only. Here are two object of arrays:

var arrA = [
   {Name: "A"},
   {Name: "C"},
   {Name: "F"},
   {Name: "G"},
]

var arrB = [
   {Name: "C"},
   {Name: "J"},
   {Name: "I"},
]

Here is the result I am expecting:

[
   {Name: "A"},
   {Name: "F"},
   {Name: "G"},
]

Please advise. Thank you.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Definitely not the most efficient way in terms of performance but not a bad approach if lines of code is what you pay attention to.

var arrA = [{Name: "A"}, {Name: "C"}, {Name: "F"}, {Name: "G"}];
var arrB = [{Name: "C"}, {Name: "J"}, {Name: "I"}];

var result = arrA.filter(a => !arrB.some(b => b.Name === a.Name));

console.log(result);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading