title: JavaScript (Lodash) - Deep comparison of two objects
body: <p>Let's say I have two deep objects:</p>
  
  <pre><code>var oldData = {
    "id": 1,
    "first_name": "Eric",
    "last_name": "Henry",
    "info": {
      "email": "ehenry0@smh.com.au",
      "gender": "Male",
      "ip_address": "7.11.169.150",
      "age": 11
    }
  };
  
  var newData = {
    "id": 2,
    "first_name": "Tommy",
    "last_name": "Henry",
    "info": {
      "email": "tommy@ghenrry.com",
      "gender": "Male",
      "ip_address": "7.11.169.150",
      "age": 15
    }
  };
  </code></pre>
  
  <p>How would I use lodash (or JavaScript) to traverse through each object and get the value of each different value, so in the top case it would be</p>
  
  <pre><code>[
     {old: 1, new: 2},
     {old: 'Eric', new: 'Tommy'},
     {old: 'ehenry0@smh.com.au', new: 'tommy@ghenrry.com'},
     {old: 11, new: 15},
  ]
  </code></pre>
  
  <p>Here is what I have so far:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var oldData = {
    "id": 1,
    "first_name": "Eric",
    "last_name": "Henry",
    "info": {
      "email": "ehenry0@smh.com.au",
      "gender": "Male",
      "ip_address": "7.11.169.150",
      "age": 11
    }
  };
  
  var newData = {
    "id": 2,
    "first_name": "Tommy",
    "last_name": "Henry",
    "info": {
      "email": "tommy@ghenrry.com",
      "gender": "Male",
      "ip_address": "7.11.169.150",
      "age": 15
    }
  };
  
  var diffObj = _.difference(_.keys(oldData), _.keys(newData));
  
  console.log(JSON.stringify(diffObj, null, 4));</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdn.jsdelivr.net/lodash/4.17.4/lodash.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>