title: Parsing a JSON result and creating a custom object from it
body: <p><strong>UPDATE</strong></p>
  
  <blockquote>
    <p>All the solutions in this post answer my question, but I can mark only one as excepted answer... </p>
  </blockquote>
  
  <p>I have this JSON result:</p>
  
  <pre><code>[
     { 
        "unsorted1":[7,7,10,3,3]
     },
     {
        "unsorted2":[8,9,3,10,6]
     }
  ]
  </code></pre>
  
  <p>I would like to make an array in JavaScript that has each the "unsorted1" and "unsorted2" as keys, the [7,7,10,3,3] and [8,9,3,10,6] must remain in JSON format. An object like That unsorted1: [7,7,10,3,3] and unsorted2: [8,9,3,10,6]</p>
  
  <p>This is what I get in the browser using the <code>console.log(JSON.parse(returnVar));</code> the <code>returnVar</code> parameter holds my JSON result from above.</p>
  
  <p><a href="https://i.stack.imgur.com/E4t3x.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E4t3x.jpg" alt="enter image description here"></a></p>
  
  <p>I read a lot and tried a lot, but nothing comes close to what I want. Somehow I can't get it done.</p>
  
  <p>I tried modifying this code with no success </p>
  
  <pre><code>var resultObj = {};
  for (var key in returnVar) {
      if (returnVar.hasOwnProperty(key)) {
          var val = returnVar[key];
          console.log("val: " + val);
          var keyName = Object.keys(val);
          console.log("key Name: " + keyName);
          for (var keykey in val) {
              if (val.hasOwnProperty(keykey)) {
                  var valval = val[keykey]
                  resultObj[keyName] = JSON.stringify(valval);
              }
          }
      }
  }
  </code></pre>