title: Copying selected property values of one object to another
body: <p>I have 2 javascript objects: obj_a and obj_b:</p>
  
  <pre><code>var obj_a = {'p1':{x:100, y:200, z:100}, 'p2':{x:100, y:100, z:300}};
  var obj_b = {'p1':{x:100, y:200}, 'p2':{x:100, y:100}};
  </code></pre>
  
  <p>I'm trying to copy only "x and y values" of obj_b to obj_a if they're different.
  For example, </p>
  
  <p>if <code>obj_b = {'p1':{x:200, y:200}, 'p2':{x:300, y:400}};</code>, </p>
  
  <p>final obj_a will be <code>obj_a = {'p1':{x:200, y:200, z:100}, 'p2':{x:300, y:400, z:300}};</code>. completely ignoring the property "z" of obj_a. </p>
  
  <p>So, I've written the following:</p>
  
  <pre><code>function isDifferent(a, b) {
      var aProps = Object.getOwnPropertyNames(a);
      var bProps = Object.getOwnPropertyNames(b);
      for (var i = 0; i &lt; bProps.length; i++) {
          var propName = bProps[i];
           if (a[propName] != b[propName]) {
              return true;
          }
      }
      return false;
  }
  for (var prop in obj_b){
      if(isDifferent(obj_a[prop], obj_b[prop]){
          var bProps = Object.getOwnPropertyNames(obj_b[prop]);
          for (var i = 0; i &lt; bProps.length; i++){
              var propName = bProps[i];
              obj_a[prop].propName = obj_b[prop].propName;
          }
      }
  }
  </code></pre>
  
  <p>But there's a problem in copying using obj_a[prop].propName since I only get undefined when I <code>console.log(obj_a[prop].propName);</code>. When I tried <code>console.log(obj_a[p1].x);</code>, the output is the old value: "200". Can somebody enlighten me?</p>