title: In Javascript remove keys from object not in an Array
body: <p>Suppose I have a list of objects with many keys and I want to keep only certain keys from them.
  This is how I am doing it.</p>
  <p>The Problem with other good solutions on SO are that if a key is not present in the keys to keep it still adds a key, value where the value is undefined.</p>
  <pre><code>let data = [{
     'a': 1,
     'b': 2,
     'c': 3
   }, 
   {
     'a': 1,
     'c': 3,
     'd': 4
   }]
  
  const keys_to_keep = ['a', 'b']
  
  data = data.map((obj) =&gt; {
    Object.keys(obj).forEach(function(key) {
      if(!keys_to_keep.includes(key))
        delete obj[key]
    });
    return obj;
  })
  </code></pre>
  <p>Output :</p>
  <pre><code>[ { a: 1, b: 2 }, { a: 1} ]
  </code></pre>
  <p>Is there a better way to get this done.
  Any help is appreciated.</p>