javascript - Is it possible to change the order of parents/childs in an object with items? -


i have object looks this:

sum = {   value:{        a: 10,       b: 11   }   value2:{        a: 33,       c: 12   }   .. } 

my object more complex, letters contains objects different values, key thing that, wish loop through letters exist in every value , return objects like:

a:{   value: 10,   value2: 33 } 

i loop through entire thing build new object, there more effient way of "flipping objects order?

i want use keys present in value-objects, them this, not requirement.

value = ['value', 'value2'] tags.foreach( (tag) =>     keys.push(object.keys(sum[tag])) ) matches = _.intersection.apply(_, keys);   matches.foreach( (match) => {   ... } 

this solution features reorganisation of order of properties.

grouped[kk][k] = sum[k][kk] elements 

var sum = {          value: {              a: 10,              b: 11          },          value2: {              a: 33,              c: 12          }      },      grouped = {};    object.keys(sum).foreach(function (k) {      object.keys(sum[k]).foreach(function (kk) {          grouped[kk] = grouped[kk] || {};          grouped[kk][k] = sum[k][kk];      });  });  document.write('<pre>' + json.stringify(grouped, 0, 4) + '</pre>');


Comments