Files
30-seconds-of-code/snippets/object-from-pairs.md
Stefan Feješ f559030eac fix naming
2017-12-17 15:41:31 +01:00

9 lines
236 B
Markdown

### Object from key-value pairs
Use `Array.reduce()` to create and combine key-value pairs.
```js
const objectFromPairs = arr => arr.reduce((a, v) => (a[v[0]] = v[1], a), {});
// objectFromPairs([['a',1],['b',2]]) -> {a: 1, b: 2}
```