Update zipObject.md

This commit is contained in:
Angelos Chalaris
2017-12-21 11:13:38 +02:00
committed by GitHub
parent 3cf7ce0118
commit 2f1193915e

View File

@ -1,8 +1,8 @@
### zipObject
Given an array of valid property identifiers and an array of values, `zipObject` returns an object associating the properties to the values
Given an array of valid property identifiers and an array of values, return an object associating the properties to the values.
Since an object can have undefined values but not undefined property pointers, the array of properties is used to decide the structure of the resulting object through a `reduce`
Since an object can have undefined values but not undefined property pointers, the array of properties is used to decide the structure of the resulting object using `Array.reduce()`.
```js
const zipObject = ( props, values ) => props.reduce( ( obj, prop, index ) => ( obj[prop] = values[index], obj ), {} )