title: how to collect data from json objects with multiple keys and push all values to single key:value array
body: <p>I have a sample json object: </p>
  
  <pre><code>var jsonString = '[{ "name":"John", "age":30, "car":Mercedes},{ "name":"Jimy", "age":32, "car":Audi},{ 
  "name":"Mia", "age":22, "car":Renault},{ "name":"Frank", "age":35, "car":null }]';
  
  var data = JSON.parse(jsonString);
  </code></pre>
  
  <p>I would like to grab latest two data from the data array and create a single key:value array so that for each json property there is a key in the array, and all the values from all the json objects are stored under their appropriate key, so for example, the result I Would like to have is generically array [{key: data_array_for_that_key}] or specifically:</p>
  
  <pre><code>output=[{name: [Frank, Mia]}, {age: [35,22]}, {car: [null, Renault]}......]
  </code></pre>
  
  <p>I've tried something like this:</p>
  
  <pre><code>var output = [];
  
    data.slice(-2).forEach((d, i) =&gt; {
      Object.keys(d).forEach((key) =&gt; {
        output.push({[key] : d[key]});
      });
    });
    console.log(output);
  </code></pre>
  
  <p>but it creates a key and value for each json object which is not what I want.</p>
  
  <p>How can I solve this?</p>