1.0.2 • Published 8 years ago

array-key-hash v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

array-key-hash Build Status

Get the id keys out of an array and create a hash of the values

Install

$ npm install --save array-key-hash

Usage

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