title: What is the most efficient way of creating an object with a subset of properties, based on an array of property names in javascript?
body: <p>In the following example (which does what I require), I'm looping the properties of an object, and creating a new object which has just the properties included in the selectedProperties array.</p>
  <p>Is there a more efficient way to do this? I have looked at Object Destructuring, but I'm not sure how this applies if you have an array of resulting properties like this.</p>
  <pre><code>const bigObject = {
    prop1: &quot;value1&quot;,
    prop2: &quot;value2&quot;,
    prop3: &quot;value3&quot;,
    prop4: &quot;value4&quot;
  }
  
  const selectedProperties = ['prop1', 'prop4'];
  
  result = {};
  Object.keys(bigObject).forEach((propertyName)=&gt;{
      if(selectedProperties.includes(propertyName)){
          result[propertyName] = bigObject[propertyName];
    }
  });
  
  console.log(result);
  </code></pre>
  <p>Output:</p>
  <pre><code>{
    prop1: &quot;value1&quot;,
    prop4: &quot;value4&quot;
  }
  </code></pre>