Files
30-seconds-of-code/snippets/objectFromPairs.md
2018-09-08 11:59:01 +04:00

298 B

objectFromPairs

Creates an object from the given key-value pairs.

Use Array.reduce() to create and combine key-value pairs.

const objectFromPairs = (arr) => arr.reduce((a, [key, val]) => ((a[key] = val), a), {});
objectFromPairs([['a', 1], ['b', 2]]); // {a: 1, b: 2}