Skip to content

Converts an array to an object where the keys are the array entries and the values are customizable in a function.

License

Notifications You must be signed in to change notification settings

Jaid/array-to-object-keys

Repository files navigation

array-to-object-keys

License Sponsor array-to-object-keys
Build status Commits since v1.3.7 Last commit Issues
Latest version on npm Dependents Downloads

Converts an array to an object where the keys are the array entries and the values are customizable in a function.

Installation

array-to-object-keys on npm

npm install --save array-to-object-keys@^1.3.7

array-to-object-keys on Yarn

yarn add array-to-object-keys@^1.3.7

@jaid/array-to-object-keys on GitHub Packages
(if configured properly)

npm install --save @jaid/array-to-object-keys@^1.3.7

Example

import arrayToObjectKeys from "array-to-object-keys"

const array = ["a", "b"]
const result = arrayToObjectKeys(array, (key, index) => {
  return `#${index} - ${key}`
})

Variable result will be:

{
  a: "#0 - a",
  b: "#1 - b",
}

Development

Setting up:

git clone [email protected]:jaid/array-to-object-keys.git
cd array-to-object-keys
npm install

Testing:

npm run test:dev

Testing in production environment:

npm run test

License

MIT License
Copyright © 2020, Jaid [email protected] (github.com/jaid)