title: match an object in an array of objects and remove
body: <p>After 2 days of fighting this problem I'm hoping someone can help me out.</p>
  
  <p>I have two arrays of objects, like this:</p>
  
  <pre><code>let oldRecords = [
    {name: 'john'},
    {name: 'ringo'}
  ];
  
  let newRecords = [
    {name: 'paul'},
    {name: 'john'},
    {name: 'stuart'}
  ];
  </code></pre>
  
  <p>I am trying to end up with a function that returns named variables containing a list of data thats been added (exist in <code>newRecords</code> but not in <code>oldRecords</code>) and a list of data that has been removed (exists in <code>oldRecords</code> but not in <code>newRecords</code>). </p>
  
  <p>for example</p>
  
  <pre><code>const analyse = (older, newer) =&gt; {
    let added, removed;
      // ... magic
    return {added, removed}
  }
  
  const {added, removed} = analyse(oldRecords, newRecords);
  </code></pre>
  
  <p>I won't post all the code I've tried inside this function as I have tried to map, reduce and loop through both arrays creating temporary arrays for the last 48 hours and I could now fill a book with code I've written and deleted. I have also used underscore.js methods like <code>reject</code>/<code>find</code>/<code>findWhere</code> which all got me close but no cigar.</p>
  
  <p>the main issue I am having is because the arrays contain objects, its super easy if they contain numbers, i.e.</p>
  
  <pre><code>var oldRecords = [1, 3];
  var newRecords = [1, 2, 4]
  
  function analyse (old, newer) { 
    let added = [];
    let removed = [];
  
    old.reduce((o) =&gt; {
      added = added.concat(_.reject(newer, (num) =&gt; num === o ));
    });
  
    newer.reduce((n) =&gt; {
      removed = _.reject(old, (num) =&gt; num === n );
    });
  
    return {added, removed}
  }
  
  const {added, removed} = analyse(oldRecords, newRecords);
  </code></pre>
  
  <p>How can I achieve the above but with objects not arrays?</p>
  
  <p>n.b. I tried modifying the above and using <code>JSON.stringify</code> but it didn't really work.</p>
  
  <p><strong>EDIT</strong>: important point I forgot to add, the object structure adn it's <code>keys</code> are dynamic, they come from a database, so any individual checking of a <code>key</code> must also be dynamic, i.e. not a hard coded value</p>