Similarity between arrays, object from key-value pairs
This commit is contained in:
8
snippets/object-from-key-value-pairs.md
Normal file
8
snippets/object-from-key-value-pairs.md
Normal 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]};} ));
|
||||
```
|
||||
Reference in New Issue
Block a user