Socket
Socket
Sign inDemoInstall

arr-to-obj

Package Overview
Dependencies
6
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    arr-to-obj

convert arrays to objects (arr to obj)


Version published
Weekly downloads
9
increased by28.57%
Maintainers
1
Install size
125 kB
Created
Weekly downloads
 

Readme

Source

array to object (arr to obj)

convert arrays to objects

default

(also can be used as valAsKeyAndVal)
const arrToObj = require('arr-to-obj')
const obj = arrToObj(['eh', 'canada'])
// {eh: eh, canada: canada}

valAsKey

const {valAsKey} = require('arr-to-obj')
const obj = valAsKey(['eh', 'canada'], 'woot')
// {eh: 'woot', canada: 'woot'}

valAsVal

// @example:
// var array = ['eh', 'canada']
// valAsVal(array)
const {valAsVal} = require('arr-to-obj')
const obj = valAsVal(['eh', 'canada'])
// {'1': 'eh', '2': 'canada'}

custom

const arrToObj = require('arr-to-obj')
const arr = ['eh', 'canada']

// does the same as #valAsKey
// {eh: 'woot', canada: 'woot'}
const obj = arrToObj(array, {
  valFn: () => undefined,
  keyFn: ({i, val}) => typeof fn === 'function' ? fn(val, i) : (fn || i),
})

resources

  • https://www.npmjs.com/package/array-to-object (outdated, not customizable)

Keywords

FAQs

Last updated on 23 Mar 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc