title: angularjs - copy common properties from one object to another
body: <p>I have a controller like this:</p>
  
  <pre><code>CheckoutController = function() {
      $scope.Profile = {
          firstname : 'Ruchir',
          middlename : 'Shakun',
          lastname : 'Gupta',
          email : 'ruchir@example.com',
          cellphone : '9876543210'
      }
  
      $scope.BillingDetails = {
          firstname : undefined,
          middlename : undefined,
          lastname : undefined,
          addressline : undefined,
          city : undefined,
          zipcode : undefined
      }
  
      $scope.update = function() {
          // I want to write some awesome code here as explained below
      }
  }
  </code></pre>
  
  <p>Now, in the <code>$scope.update</code> function; I want to write something that should copy '<strong>only common properties</strong>' i.e. <code>firstname</code>, <code>middlename</code>, and <code>lastname</code> from <code>$scope.Profile</code> to <code>$scope.BillingDetails</code>.</p>
  
  <p>I tried <code>angular.copy</code> and <code>angular.extend</code> but,</p>
  
  <ul>
  <li><p><code>angular.extend</code> merges <code>$scope.BillingDetails</code> and <code>$scope.Profile</code>.
  So I get <code>email</code> and <code>cellphone</code> properties in <code>$scope.BillingDetails</code> as
  well -- what I don't want. </p></li>
  <li><p><code>angular.copy</code> overwrites
  <code>$scope.BillingDetails</code> and I lose <code>addressline</code>, <code>city</code> and
  <code>zipcode</code> from <code>$scope.BillingDetails</code> -- what I don't want.</p></li>
  </ul>
  
  <p>What I want my <code>update</code> function to do is it should make <code>$scope.BillingDetails</code> equal to below object:</p>
  
  <pre><code>{
      firstname : 'Ruchir',
      middlename : 'Shakun',
      lastname : 'Gupta',
      addressline : undefined,
      city : undefined,
      zipcode : undefined    
  }
  </code></pre>
  
  <p>This scenario is just an example. To shorten the length of my question, I have mentioned 5-6 properties only. In fact, I have to deal with more than 20 properties and all are dynamic. So it won't work for me by copying one-by-one properties <code>firstname</code>, <code>middlename</code> and <code>lastname</code> from <code>Profile</code> to <code>BillingDetails</code>. 
  What can I do?</p>