-4

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.

Anon_J
  • 29
  • 1
  • 9
  • 2
    Please visit the [help], take the [tour] to see what and [ask]. Do some research - [search SO for answers](https://www.google.com/search?q=compare+two+arrays+of+objects+and+output+differences+site:stackoverflow.com). If you get stuck, post a [mcve] of your attempt, noting input and expected output using the [\[<>\]](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan Aug 15 '23 at 14:34

1 Answers1

0

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);
Behemoth
  • 5,389
  • 4
  • 16
  • 40