Similarity between arrays, object from key-value pairs

This commit is contained in:
Angelos Chalaris
2017-12-10 15:02:07 +02:00
parent f663d8494b
commit a0b7068cc1
4 changed files with 38 additions and 2 deletions

View File

@ -0,0 +1,8 @@
### 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 => {return {[v[0]] : v[1]};} ));
```