Mapping an array of objects to key/value pairs in CoffeeScript
var arr = [{name: ‘a’, value: ‘b’, other: ‘c’}, {name: ‘d’, value: ‘e’, other: ‘f’}]; var obj = arr.reduce(function ( total, current ) { total[ current.name ] = current.value; return total; }, {}); Pure javascript. It’s practically a one liner, and it looks hawt. Array.prototype.reduce is ES5, but isn’t difficult to shim. Here’s an example … Read more