Socket
Book a DemoInstallSign in
Socket

group-array-by

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

group-array-by

Takes an array and returns an object with values grouped into arrays by passing each value to `getKey` to determine to which group the value belongs.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

group-array-by

Takes an array and returns an object with values grouped into arrays by passing each value to getKey to determine to which group the value belongs.

install

$ npm install group-array-by

example

const groupBy = require('group-array-by')

groupBy(v => v.type, [
  { type: 'coffee', roast: 'light' },
  { type: 'coffee', roast: 'medium' },
  { type: 'juice', fruit: 'grape' },
  { type: 'coffee', roast: 'dark' }
])
/* => {
  coffee: [
    { type: 'coffee', roast: 'light' },
    { type: 'coffee', roast: 'medium' },
    { type: 'coffee', roast: 'dark' }
  ],
  juice: [
    { type: 'juice', fruit: 'grape' }
  ]
} */

api

groupBy(getKey, array)

  • getKey(value)
    • value an item from the array
    • => key the key the item should be grouped under
  • array: [] the array to group into an object
  • => object the object of grouped values

Keywords

group

FAQs

Package last updated on 06 Apr 2017

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