Update object-from-key-value-pairs.md

This commit is contained in:
Angelos Chalaris
2017-12-12 16:03:41 +02:00
committed by GitHub
parent 0ba89f846b
commit b70be97350

View File

@ -1,8 +1,7 @@
### Object from key-value pairs
Use `map()` to create objects for each key-value pair, combine with `Object.assign()`.
Use `Array.reduce()` to create and combine key-value pairs.
```js
var objectFromPairs = arr =>
Object.assign(...arr.map( v => ({ [v[0]] : v[1] })));
const objectFromPairs = arr => arr => arr.reduce((a,b) => { a[b[0]] = b[1]; return a;}, {})
```