Created
September 11, 2017 08:20
-
-
Save olehwebdev/8e3e2019d0384411dc0e792d6ff341ff to your computer and use it in GitHub Desktop.
Converting an array to an object from key-value pairs
This file contains hidden or 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
const pairs = [['a', 1], ['b', 2], ['c', 3]]; | |
const asObject = pairs.reduce((res, [key, value]) => ({...res, [key]: value }), {}) | |
const asObject2 = { ...(new Map(pairs)) } | |
console.log(asObject) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment