Last active
May 25, 2022 06:56
-
-
Save aherve/c2fd93051a56c6e627668a4481a2ec85 to your computer and use it in GitHub Desktop.
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
// 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 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Как вообще конструкция
...(new Map(pairs))
может работать?Если итератор Мапы возвращает по массиву