Creates an object from the given key-value pairs.
Use Array.prototype.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}