Back to Top

array-to-objecthash master

Convert array to object hash based on specific key

module.exports(key, data)

converts an array of objects to hashed objects based on the key property of each object

 const arr = [
   {
     key: 'key_one',
     value: 'some value one'
   },
   {
     key: 'key_two',
     value: 'some value two'
   }
 ]

 const obj = convertArrayToHash(arr, 'key')

Parameters

Name Type Description
key string

the key to hash the object upon

data object array

array or object with a property key to map upon

Returns

object