1.0.2 • Published 9 years ago
array-key-hash v1.0.2
array-key-hash 
Get the id keys out of an array and create a hash of the values
Install
$ npm install --save array-key-hashUsage
var arrayKeyHash = require('array-key-hash')
const items = [
{id: 1, foo: 'a'},
{id: 2, foo: 'b'}
]
const itemsById = arrayKeyHash(items)
console.log(itemsById)
// => {1: {id: 1, foo: 'a'}, 2: {id: 2, foo: 'b'}}API
arrayKeyHash(array, [idKey]) -> object
array
Required
Type: array
idKey
Type: string
The key to index the resulting hash by. Defaults to 'id'.
Returns object
An object with keys representing ids of items in array, and values being the values of those items.
Related / Recommended
License
MIT © Andrew Joslin