title: tested keys inside JavaScript object for API
body: <p>I am trying to get a json object returned from this function here's the code this runs and logs for example "firstname john" which is what i am expecting.</p>
  
  <pre><code>var req = { 'body' : {
      'firstname':'john',
      'middlename':'matrix',
      'lastname':'smith',
      'test' :'jesus'}
      };
  
  var targets = ['firstname' , 'middlename', 'lastname'];
  
  for (var i = 0; i &lt; Object.keys(req.body).length; i++) {
      if(targets.includes(Object.keys(req.body)[i])){
          console.log(Object.keys(req.body)[i], req.body[Object.keys(req.body)[i]]);
      }
  }
  </code></pre>
  
  <p>if i make the console.log() log an object instead of a string for example:</p>
  
  <pre><code>console.log({Object.keys(req.body)[i] : req.body[Object.keys(req.body)[i]]});
  </code></pre>
  
  <p>it throws a syntax error, is there a better way to do this/how can i get this to work?</p>