title: Is there a proper way to clone certain primitive properties of an object in JavaScript?
body: <p>I need a simple function to map a list of primitive properties from one object to another. I wrote one myself, but I guess there's already a proven method to achieve this.</p>
  
  <pre><code>var mapProperties = function (props, from) {
      var to = {};
  
      for (var i = 0; i &lt; props.length; i++) {
          to[props[i]] = from[props[i]];
      }
  
      return to;
  }
  </code></pre>
  
  <p>Then use the function like:</p>
  
  <pre><code>var fromObj = {
     foo: "foo",
     bar: 1
  }
  
  var toObj = mapProperties(['foo', 'bar'], fromObj);
  </code></pre>
  
  <p>Any better ideas?</p>