# group-by

> Group an array by property values or callback

Latest version **0.0.1** (published 2012-10-06) · 0 weekly downloads

## Install

```sh
npm install group-by
pnpm add group-by
yarn add group-by
bun add group-by
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2012-10-06 |
| First published | 2012-10-06 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | tjholowaychuk |

## Links

- npm: https://www.npmjs.com/package/group-by
- npm.io page: https://npm.io/package/group-by

## Dependencies (1)

- [to-function](https://npm.io/package/to-function.md) *

## Recent versions

- 0.0.1 (latest) — 2012-10-06

## README

# group-by

  Group an array of values by property or callback function.

## Installation

    $ component install component/group-by
    $ npm install group-by

## API

### groupBy(array, prop)

  Map returning a new array:

```js
var groupBy = require('group-by');

var log1 = { type: 'log', version: '1.0.0' };
var log2 = { type: 'log', version: '1.1.0' };
var log3 = { type: 'log', version: '1.3.0' };
var app1 = { type: 'app', version: '1.0.0' };
var app2 = { type: 'app', version: '1.1.0' };

var nodes = [log1, app1, log2, log3, app2];

groupBy(nodes, 'type');
```

yields:

```js
{ log: 
   [ { type: 'log', version: '1.0.0' },
     { type: 'log', version: '1.1.0' },
     { type: 'log', version: '1.3.0' } ],
  app: 
   [ { type: 'app', version: '1.0.0' },
     { type: 'app', version: '1.1.0' } ] }
```

### groupBy(array, fn)

  Group with an arbitrary `fn`, returning a key name:

```js
groupBy(users, function(user){
  return user.pets.length
    ? 'hasPets'
    : 'noPets';
})
```

# License

  MIT

---
_Source: https://npm.io/package/group-by · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
