Array.reduce to populate an object

An easy way to populate an object from a collection is to use reduce:

var collection = [{id: 1, value: 'foo'}, {id: 2, value: 'bar'}];

var result = collection.reduce(function reducer(obj, item) {
  obj[item.id] = item.value;

  return obj;
}, {});

console.log(result); // {1: 'foo', 2: 'bar'}