Im looking for your advise how to re-build object in javascript/jquery? Im receiving JSON from server 

Source json (var array):

```
{  
  "key1":{  
         "subkey1":"a",
         "subkey2":"b",
      },
  "key2":{  
         "subkey1":"a",
         "subkey2":"a",
      }
}

```

Expected object:

```
{  
  "a":{  
         "subkey1":[
                      "key1",
                      "key2",
                   ],
         "subkey2":[
                      "key2"
                   ]
      },
  "b":{  
         "subkey2":[
                      "key1"
                   ]
      }
}

```

Here is where I got stuck:

```
    var newarray = {};
    for (var key in array) {
        var items = [];
        for (var item_id in array[key]) {
            items.push(item_id);
            newarray[array[key][item_id]] = [];
        }
        console.log(items);
    }
    console.log(newarray);

```