Create an object from an array of objects indexed by a chosen key
npm install index-by
var chickens = [
{ name: 'Gurli', hunger: 3 },
{ name: 'Obik', hunger: 1 },
{ name: 'Lui', hunger: 5 },
];
var indexBy = require('index-by');
indexBy(chickens, 'name');
// { Gurli: .., Obik: .., Lui: .. }
indexBy(chickens, [ 'name', 'hunger' ]);
// { 'Gurli.3': .., 'Obik.1': .., 'Lui.5': .. }
indexBy(chickens, callback);
// index by the return value of: callback(currentValue, index, array)
indexBy.path(list, 'path.to.key');
// index by a deep key
All functions take a third argument map
which is an existing map to
amend
MIT © src.agency / Thomas Jensen