Q:

Convert array of object to object with keys

say I have an array :
[ { name: 'A', count: 100 }, { name: 'B', count: 200 } ]

how can I get an object :
{ A : 100, B : 200 }

A:

Try utilizing Array.prototype.forEach() to iterate properties , values of array , set properties of new object to properties , values of input array
var arr = [ { name: 'A', count: 100 }, { name: 'B', count: 200 } ];
// create object 
var res = {};
// iterate `arr` , set property of `res` to `name` property of 
// object within `arr` , set value of `res[val.name]` to value
// of property `count` within `arr`
arr.forEach(function(val, key) {
  res[val.name] = val.count
});
console.log(res);

