Q:

Assigning two dynamic keys to an array

I've been trying to do this for an hour now and I can't figure it out.
I have this:
data =  [
      {
        "_id": {
          "cid": "gbrzjauzju",
          "source": "iwowrzlocc"
        },
        "revenue": 0,
        "leads": 484,
        "count": 25400
      },
      {
        "_id": {
          "cid": "lewyhgnnhz",
          "source": "iwowrzlocc"
        },
        "revenue": 0,
        "leads": 166,
        "count": 9821
      },
    ]

I am passing in filters as variable filters with ['cid', 'source'] so I can access it as filters[0] filters[1]
What I am trying to do this is:
arr = {}
for item in data
   arrdata =
      revenue: item.revenue
      leads: item.leads
      clicks: item.count
   arr['results'][item._id.filters[0]][item._id.filters[1]] = arrdata

I want to set the value of cid and source as the key names as the key name so it would be like this:
results =
   iwowrzlocc =
      lewyhgnnhz =
         revenue: 0
         leads: 166
         clicks: 9821
      gbrzjauzju =
         revenue: 0
         leads: 484
         clicks: 25400

How exactly would I accomplish this? Thank you in advance!

A:

Have you tried to not use the "dot syntax" in item._id.filters[0]?
If I were you, I'd try to split the last statement:
var arr = {};
var item_results = {};
var item_cid = {};
for (i in data) {
    var item = data[i];
    var array_data = {
        revenue: item.revenue,
        leads: item.leads,
        count: item.count
    };
    item_cid[item._id[filters[1]]] = array_data;
    item_results[item._id[filters[0]]] = item_cid;
};
arr['results'] = item_results;

Just to make things more readable and easier to identify possible problems in your code. I hope I could help you in some way! :)

