say I have an array :
[ { name: \'A\', count: 100 }, { name: \'B\', count: 200 } ]
how can I get an object :
{ A : 100, B : 200
Looks like a great opportunity to practice using Array.prototype.reduce (or reduceRight, depending on desired behaviour)
[{name: 'A', count: 100}, {name: 'B', count: 200}].reduceRight(
function (o, e) {o[e.name] = e.count; return o;},
{}
); // {B: 200, A: 100}
This could also be easily modified to become a summer,
o[e.name] = (o[e.name] || 0) + e.count;