Created
February 24, 2015 18:23
-
-
Save estliberitas/ec3efc60a73e12a6b0c8 to your computer and use it in GitHub Desktop.
Array to Object using Array#reduce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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