Files
30-seconds-of-code/snippets/object-from-key-value-pairs.md
2017-12-12 08:08:09 +01:00

9 lines
216 B
Markdown

### Object from key-value pairs
Use `map()` to create objects for each key-value pair, combine with `Object.assign()`.
```js
var objectFromPairs = arr =>
Object.assign(...arr.map( v => ({ [v[0]] : v[1] })));
```