New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

groupby-array

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

groupby-array

Groups an array by the specified property

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

groupby-array

Groups an array by the specified property.

NPM Version Action Status Coverage Status License

Installation

yarn add groupby-array

or

npm install --save groupby-array

Usage

Basic usage

import { groupBy } from 'groupby-array';

const users = [
  { name: 'John', age: 30, isAdmin: true },
  { name: 'Jane', age: 25, isAdmin: true },
  { name: 'Jim', age: 30, isAdmin: false }
];
  
const result = groupBy(users, u => u.age);
// result

{
  30: [
    { name: 'John', age: 30, isAdmin: true },
    { name: 'Jim', age: 30, isAdmin: false }
  ],
  25: [
    { name: 'Jane', age: 25, isAdmin: true }
  ]
};

Group by multiple properties

const users = [
  { firstName: 'John', lastName: 'Doe', age: 30 },
  { firstName: 'Jane', lastName: 'Doe', age: 25 },
  { firstName: 'James', lastName: 'Bond', age: 30 }
];
  
const result = groupBy(users, u => `${u.firstName} ${u.lastName}`);
// result

{
  'John Doe': [
    { firstName: 'John', lastName: 'Doe', age: 30 }
  ],
  'Jane Doe': [
    { firstName: 'Jane', lastName: 'Doe', age: 25 }
  ],
  'James Bond': [
    { firstName: 'James', lastName: 'Bond', age: 30 }
  ]
};

More examples can be found in the tests

Keywords

array

FAQs

Package last updated on 09 Dec 2021

Did you know?

Socket

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.

Install

Related posts