Skip to content

Florian77/index-by

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Index an array of objects

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%