Files
30-seconds-of-code/snippets/object-from-key-value-pairs.md
Angelos Chalaris e2d2b6aa41 Updated snippets
Mainly for better readability
2017-12-12 18:21:53 +02:00

235 B

Object from key-value pairs

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

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