Socket
Socket
Sign inDemoInstall

nested-groupby

Package Overview
Dependencies
2
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    nested-groupby

A multi-level groupBy for arrays. Nesting allows elements in an array to be grouped into a hierarchical tree structure; think of it like the GROUP BY operator in SQL, except you can have multiple levels of grouping, and the resulting output is a tree rath


Version published
Weekly downloads
50
increased by257.14%
Maintainers
1
Install size
138 kB
Created
Weekly downloads
 

Readme

Source

Nested Groupby


Nested Groupby is a node module to group objects in an array similar to Lodash's groupBy method, but to group the objects by more than one key.

Examples


See this Codepen for demo.


        import nestedGroupby from 'nested-groupby';
        // For commonjs
        // const nestedGroupby = require('nested-groupby');

        const data = [
          { type: 'apple', color: 'green', quantity: 1000 },
          { type: 'apple', color: 'red', quantity: 2000 },
          { type: 'grape', color: 'green', quantity: 1000 },
          { type: 'grape', color: 'red', quantity: 4000 },
        ];

        nestedGroupby(data, ['type', 'color']);

        // output will be the following
        // {
        //   apple: {
        //     green: [ { type: 'apple', color: 'green', quantity: 1000 } ],
        //     red: [ { type: 'apple', color: 'red', quantity: 2000 } ]
        //   },
        //   grape: {
        //     green: [ { type: 'grape', color: 'green', quantity: 1000 } ],
        //     red: [ { type: 'grape', color: 'red', quantity: 4000 } ]
        //   }
        // }

FAQs

Last updated on 18 Jul 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc