https://github.com/jonkemp/from-pairs
Convert arrays into objects
https://github.com/jonkemp/from-pairs
array arrays keys object objects pairs util utility
Last synced: 3 months ago
JSON representation
Convert arrays into objects
- Host: GitHub
- URL: https://github.com/jonkemp/from-pairs
- Owner: jonkemp
- License: mit
- Created: 2020-03-20T13:14:57.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-06T01:32:56.000Z (5 months ago)
- Last Synced: 2025-04-28T15:14:47.098Z (3 months ago)
- Topics: array, arrays, keys, object, objects, pairs, util, utility
- Language: JavaScript
- Size: 191 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# from-pairs 
> Convert arrays 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
Install with [npm](https://npmjs.org/package/from-pairs)
```
$ npm install from-pairs
```Or [unpkg](https://unpkg.com/from-pairs/)
```
```
Check out the unit tests on [CodePen](https://codepen.io/jonkemp/full/LYVBdrJ).
## Usage
```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) |
| ----------------------------------------------------------------------------------------------------------------------------------------- | --- | --------------------------------------------------------------------------------------------------------------------- |## API
### fromPairs(list)
#### list
Type: `array`
Default: `none`The key-value pairs.
## License
MIT