0.0.1 • Published 10 years ago

index-by v0.0.1

Weekly downloads
6
License
MIT
Repository
github
Last release
10 years ago

indexBy

Create an object from an array of objects indexed by a chosen key

Install

npm install index-by

Usage

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

License

MIT © src.agency / Thomas Jensen