
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
group-array
Advanced tools
Group array of objects into lists.
Install with npm
$ npm i group-array --save
var groupArray = require('group-array');
Create groupings from array's values.
Params
arr
{Array}: Array to group.grouper
{Function}: Optional grouping function that takes acc, value, i, arr, setter
setter
{Function}: Optional setter function that takes acc, group, value, i, arr
acc
{Object|Array}: Optional accumulator object or array passed to the setter function.returns
{Object|Array}: Object or array containing groups as keys and list of objects as values in the group.Example
function grouper (acc, value, i, arr, setter) {
return value.group;
}
function setter (acc, group, value, i, arr) {
acc[group] = acc[group] || [];
acc[group].push(value);
}
var arr = [
{ group: 'one', content: 'A'},
{ group: 'one', content: 'B'},
{ group: 'two', content: 'C'},
{ group: 'two', content: 'D'},
{ group: 'three', content: 'E'},
{ group: 'three', content: 'F'}
];
var groups = groupBy(arr, grouper, setter);
//=> {
//=> one: [
//=> { group: 'one', content: 'A'},
//=> { group: 'one', content: 'B'}
//=> ],
//=> two: [
//=> { group: 'two', content: 'C'},
//=> { group: 'two', content: 'D'}
//=> ],
//=> three: [
//=> { group: 'three', content: 'E'},
//=> { group: 'three', content: 'F'}
//=> ]
//=> }
a.b.c
) to get a nested value from an object.Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Brian Woodward
Copyright © 2015 Brian Woodward Released under the MIT license.
This file was generated by verb-cli on July 19, 2015.
FAQs
Group array of objects into lists.
We found that group-array demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.