obj-from-arr
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Create object from array Travis CI Build Status

Convert an array to an object based on the return value of an iteratee.

NPM Badge

Install

npm install obj-from-arr

Usage

const objFromArr = require("obj-from-arr");
 
objFromArr(["a", "b", "c"], val => {
    // Handle array here. I'm going to use some simple handling logic as an example.
    if (val === "a") return 1;
    if (val === "b") return 2;
    if (val === "c") return 3;
});
//=> { "a": 1, "b": 2, "c": 3 }

API

objFromArr(array, iteratee)

arr

Type: array

The array to convert.

iteratee

Type: function<Array.map>

The iteratee to use when iterating through the array.

Package Sidebar

Install

npm i obj-from-arr

Weekly Downloads

4

Version

1.0.1

License

MIT

Unpacked Size

3.72 kB

Total Files

6

Last publish

Collaborators

  • richienb