Skip to content

Instantly share code, notes, and snippets.

@olehwebdev
Created September 11, 2017 08:20
Show Gist options
  • Save olehwebdev/8e3e2019d0384411dc0e792d6ff341ff to your computer and use it in GitHub Desktop.
Save olehwebdev/8e3e2019d0384411dc0e792d6ff341ff to your computer and use it in GitHub Desktop.
Converting an array to an object from key-value pairs
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