I'm using node.js and lodash.
I have data like this:
[
{
to: [ '[email protected]', '[email protected]' ],
submittedSubs: [ [Object] ]
},
{
to: [ '[email protected]', '[email protected]' ],
submittedSubs: [ [Object], [Object], [Object] ]
}
]
I'd like to turn it into data like this where it's "sorted" by to
[
{
to: '[email protected]',
submittedSubs: [ [Object],[Object], [Object], [Object] ]
},
{
to: '[email protected]',
submittedSubs: [ [Object] ]
},
{
to: '[email protected]',
submittedSubs: [ [Object], [Object], [Object] ]
}
]
How can I do this?
I've tried this:
spam[0].to.push('[email protected]');
spam[0].to.push('[email protected]');
spam[1].to.push('[email protected]');
spam[1].to.push('[email protected]');
console.log('data is',spam);
var byUser=[];
_.each(spam, function(data){
_.each(data.to,function(addr){
byUser.push({to:addr,submittedSubs:data.submittedSubs});
});
});
console.log('attempt',_.merge(byUser));
But that gives me this:
[ { to: '[email protected]', submittedSubs: [ [Object] ] },
{ to: '[email protected]', submittedSubs: [ [Object] ] },
{ to: '[email protected]', submittedSubs: [ [Object], [Object], [Object] ] },
{ to: '[email protected]', submittedSubs: [ [Object], [Object], [Object] ] } ]
tofield.