620 B
620 B
title, tags, cover, firstSeen, lastUpdated
| title | tags | cover | firstSeen | lastUpdated |
|---|---|---|---|---|
| Object from pairs | object,array | blog_images/silver-flat-screen.jpg | 2017-12-17T17:55:51+02:00 | 2020-10-21T21:54:53+03:00 |
Creates an object from the given key-value pairs.
- Use
Array.prototype.reduce()to create and combine key-value pairs. Object.fromEntries()provides similar functionality.
const objectFromPairs = arr =>
arr.reduce((a, [key, val]) => ((a[key] = val), a), {});
objectFromPairs([['a', 1], ['b', 2]]); // {a: 1, b: 2}