title: Compare two arrays of objects, and remove if object value is equal
body: <p>I've tried modifying some of the similar solutions on here but I keep getting stuck, I believe I have part of this figured out however, the main caveat is that:</p>
  <p>Some of the objects have extra keys, which renders my object comparison logic useless.</p>
  <p>I am trying to compare two arrays of objects. One array is the original array, and the other array contains the items I want deleted from the original array. However there's one extra issue in that the second array contains extra keys, so my comparison logic doesn't work.</p>
  <p><strong>An example would make this easier, let's say I have the following two arrays:</strong></p>
  <pre><code>const originalArray = [{id: 1, name: &quot;darnell&quot;}, {id: 2, name: &quot;funboi&quot;}, 
  {id: 3, name: &quot;jackson5&quot;}, {id: 4, name: &quot;zelensky&quot;}];
  
  const itemsToBeRemoved = [{id: 2, name: &quot;funboi&quot;, extraProperty: &quot;something&quot;}, 
  {id: 4, name: &quot;zelensky&quot;, extraProperty: &quot;somethingelse&quot;}];
  </code></pre>
  <p><strong>after running the logic, my final output should be this array:</strong></p>
  <p><code>[{id: 1, name: &quot;darnell&quot;}, {id: 3, name: &quot;jackson5&quot;}]</code></p>
  <p>And here's the current code / logic that I have, which compares but doesn't handle the extra keys. How should I handle this? Thank you in advance.</p>
  <pre><code>const prepareArray = (arr) =&gt; {
    return arr.map((el) =&gt; {
      if (typeof el === &quot;object&quot; &amp;&amp; el !== null) {
        return JSON.stringify(el);
      } else {
        return el;
      }
    });
  };
  
  const convertJSON = (arr) =&gt; {
    return arr.map((el) =&gt; {
      return JSON.parse(el);
    });
  };
  
  const compareArrays = (arr1, arr2) =&gt; {
    const currentArray = [...prepareArray(arr1)];
    const deletedItems = [...prepareArray(arr2)];
    const compared = currentArray.filter((el) =&gt; deletedItems.indexOf(el) === -1);
    return convertJSON(compared);
  };
  </code></pre>