title: JavaScript: Comparing two objects
body: <p>I want to compare two objects to make a new object.</p>
  
  <pre><code>original = [
              {id: "A1", name: "Nick", age: 20, country: 'JP', code: 'PHP'}
             ]
  
  edited = [
            {name: "Mike", age: 30, country: 'US'},
            {id: "A1", name: "Nick", age: 25, country: 'US', code: 'PHP'}
           ]
  </code></pre>
  
  <ol>
  <li>Compare two objects ('original' and 'edited')</li>
  <li>If 'id' is set, compare the same ids' data, and take the data from 'edited', and get ONLY the 'id' and the data that is edited.</li>
  <li>If 'id' is not set keep the whole data</li>
  </ol>
  
  <p>The final object I want is like below;</p>
  
  <pre><code>final = [
           {name: "Mike", age: 30, country: 'US'},
           {id: "A1", age: 25, country: 'US'}
          ]
  </code></pre>
  
  <p>I've been trying this using filter, but I can't get desired result...</p>