title: Merging 2 objects into a new one, with selective condition
body: <p>I'm trying to create a new group of objects adding a new component to the first one from the second one, based on a condition. Here is an example:</p>
  <p>Have this 2 group of objects:</p>
  <pre><code>const one = [{code: 'a'},{ code: 'b'}, {code: 'c'}]
  const two = [{code: 'b', status: 'active'}]
  </code></pre>
  <p>and would like to have a result like:</p>
  <pre><code>{ code: 'a', status: 'empty' }
  { code: 'b', status: 'active' }
  { code: 'c', status: 'empty' }
  </code></pre>
  <p>This is the code I wrote as example:</p>
  <pre><code>const one = [{code: 'a'},{ code: 'b'}, {code: 'c'}]
  const two = [{code: 'b', status: 'active'}]
  
  
  
  var final = []
  var temp = {}
  
  for(let holiday of one) {
      // here I started to create a temp object with components of object one
      temp.code = holiday.code
      
      // here I check if same code from object one exist in any object two
      var checksub= two.find(o =&gt; o.code == holiday.code)
  
      // then assigns proper value to temp object from object two, of a default instead
      if(checksub){temp.status = checksub.status}
      else {temp.status = 'empty'}
  
      // then push the object into new array of objects
      final.push(temp)
  }
      
  console.log(final)
  </code></pre>
  <p>But the result I'm getting is:</p>
  <pre><code>[
    { code: 'c', status: 'empty' },
    { code: 'c', status: 'empty' },
    { code: 'c', status: 'empty' }
  ]
  </code></pre>
  <p>Why I'm getting 3 times the last object? I've tried different methods (using forEach and for loops) and always get same weird result.... what am I doing wrong?
  Thanks!!!</p>