Skip to content

Instantly share code, notes, and snippets.

@estliberitas
Created February 24, 2015 18:23
Show Gist options
  • Save estliberitas/ec3efc60a73e12a6b0c8 to your computer and use it in GitHub Desktop.
Save estliberitas/ec3efc60a73e12a6b0c8 to your computer and use it in GitHub Desktop.
Array to Object using Array#reduce
var a = [{key: 'a', value: 1}, {key: 'b', value: 2}, {key: 'c', value: 3}];
a.reduce(function(out, item) {
out[item.key] = item.value;
return out;
}, {}); // {a: 1, b: 2, c: 3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment