Skip to content

Instantly share code, notes, and snippets.

@aherve
Last active May 25, 2022 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aherve/c2fd93051a56c6e627668a4481a2ec85 to your computer and use it in GitHub Desktop.
Save aherve/c2fd93051a56c6e627668a4481a2ec85 to your computer and use it in GitHub Desktop.
// fromPairs
const pairs = [['a', 1], ['b', 2], ['c', 3]]
const asObjects = pairs
.reduce((res, [key, value]) => ({ ...res, [key]: value }), {})
// Or event smarter (thanks to @nomaed for pointing this one out)
const asObjects2 = { ...(new Map(pairs)) }
console.log(asObjects) // => { a: 1, b: 2, c: 3 }
@dimensi
Copy link

dimensi commented Sep 11, 2017

Как вообще конструкция ...(new Map(pairs)) может работать?
Если итератор Мапы возвращает по массиву

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment