Package Exports
- pluckngrouparray
- pluckngrouparray/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pluckngrouparray) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
pluckngrouparray
To pluck and group data from an array of objects in javascript in a single loop (used to remove boilerplate codes)
We can pluck any number of keys, group the array using any number of keys or even group using multiple key combimations
Sample Usage
//1)Input
const arrayOfObjects = [
{apple:1, ball:2, cat:3, dog: "hi"},
{apple:4, ball:5, cat:6, dog: "bye"}
];
const toPluckKeys = ['apple','ball'];
const groupByTheseKeysIndividually = ['apple', 'ball'];
const groupByCombinningTheseKeys = ['cat','dog'];
//2)Function call
pluckAndGroup(arrayOfObjects, toPluckKeys, groupByTheseKeysIndividually, groupByCombinningTheseKeys)));
//3)Output
{
"pluckedData": {"balls":["2","5"],"apples":["1","4"]},
"groupedByData": {
"ballgrp": {
"2":{"apple":1,"ball":2,"cat":3,"dog":"hi"},
"5":{"apple":4,"ball":5,"cat":6,"dog":"bye"}
},
"applegrp": {
"1":{"apple":1,"ball":2,"cat":3,"dog":"hi"},
"4":{"apple":4,"ball":5,"cat":6,"dog":"bye"}
}
},
"gropedByMultiKeyData": {
"cat_dogmultiGrp": {
"6_bye": {"apple":4,"ball":5,"cat":6,"dog":"bye"},
"3_hi":{"apple":1,"ball":2,"cat":3,"dog":"hi"}
}
}
}Installation
Installation is done using the
npm install command:
$ npm install pluckngrouparray