from-pairs
Version:
Convert arrays into objects.
56 lines (33 loc) • 1.56 kB
Markdown
into objects.
Pass either a single list of `[key, value]` pairs, or a list of keys, and a list of values. Passing by pairs is the reverse of pairs. If duplicate keys exist, the last value wins.
Inspired by `_.object`. 😄
Install with [npm](https://npmjs.org/package/from-pairs)
```
$ npm install from-pairs
```
Or [unpkg](https://unpkg.com/from-pairs/)
```
<script src="https://unpkg.com/from-pairs@1.0.2/umd/index.js" />
```
Check out the unit tests on [CodePen](https://codepen.io/jonkemp/full/LYVBdrJ).
```js
const fromPairs = require('from-pairs');
fromPairs(['moe', 'larry', 'curly'], [30, 40, 50]);
//=> {moe: 30, larry: 40, curly: 50}
fromPairs([['moe', 30], ['larry', 40], ['curly', 50]]);
//=> {moe: 30, larry: 40, curly: 50}
```
---
| **Like us a lot?** Help others know why you like us! **Review this package on [pkgreview.dev](https://pkgreview.dev/npm/from-pairs)** | ➡ | [](https://pkgreview.dev/npm/from-pairs) |
| ----------------------------------------------------------------------------------------------------------------------------------------- | --- | --------------------------------------------------------------------------------------------------------------------- |
Type: `array`
Default: `none`
The key-value pairs.
MIT
> Convert arrays