{"id":13393923,"url":"https://github.com/doowb/group-array","last_synced_at":"2025-04-06T00:09:09.557Z","repository":{"id":35135122,"uuid":"39344317","full_name":"doowb/group-array","owner":"doowb","description":"Group array of objects into lists.","archived":false,"fork":false,"pushed_at":"2023-10-12T16:57:17.000Z","size":49,"stargazers_count":61,"open_issues_count":1,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T23:08:36.915Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/doowb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-19T18:29:40.000Z","updated_at":"2024-07-23T03:38:14.000Z","dependencies_parsed_at":"2024-06-18T13:40:02.655Z","dependency_job_id":"b57966f5-b526-4bb0-a7e9-3c8fa7d75d72","html_url":"https://github.com/doowb/group-array","commit_stats":{"total_commits":53,"total_committers":4,"mean_commits":13.25,"dds":"0.30188679245283023","last_synced_commit":"6c2f53daff7d3b744f41ca9570a26408156cad57"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fgroup-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fgroup-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fgroup-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fgroup-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doowb","download_url":"https://codeload.github.com/doowb/group-array/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415967,"owners_count":20935387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T17:01:02.652Z","updated_at":"2025-04-06T00:09:09.534Z","avatar_url":"https://github.com/doowb.png","language":"JavaScript","readme":"# group-array [![NPM version](https://img.shields.io/npm/v/group-array.svg?style=flat)](https://www.npmjs.com/package/group-array) [![NPM monthly downloads](https://img.shields.io/npm/dm/group-array.svg?style=flat)](https://npmjs.org/package/group-array) [![NPM total downloads](https://img.shields.io/npm/dt/group-array.svg?style=flat)](https://npmjs.org/package/group-array) [![Linux Build Status](https://img.shields.io/travis/doowb/group-array.svg?style=flat\u0026label=Travis)](https://travis-ci.org/doowb/group-array)\n\n\u003e Group array of objects into lists.\n\nPlease consider following this project's author, [Brian Woodward](https://github.com/doowb), and consider starring the project to show your :heart: and support.\n\n- [Install](#install)\n- [Usage](#usage)\n- [Examples](#examples)\n- [About](#about)\n\n_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save group-array\n```\n\n## Usage\n\n```js\nvar groupArray = require('group-array');\n```\n\n## Examples\n\n```js\nvar arr = [\n  {tag: 'one', content: 'A'},\n  {tag: 'one', content: 'B'},\n  {tag: 'two', content: 'C'},\n  {tag: 'two', content: 'D'},\n  {tag: 'three', content: 'E'},\n  {tag: 'three', content: 'F'}\n];\n\n// group by the `tag` property\ngroupArray(arr, 'tag');\n```\n\n**results in:**\n\n```js\n{\n  one: [\n    {tag: 'one', content: 'A'},\n    {tag: 'one', content: 'B'}\n  ],\n  two: [\n    {tag: 'two', content: 'C'},\n    {tag: 'two', content: 'D'}\n  ],\n  three: [\n    {tag: 'three', content: 'E'},\n    {tag: 'three', content: 'F'}\n  ]\n}\n```\n\n**Group by multiple, deeply nested properties**\n\n```js\n// given an array of object, like blog posts...\nvar arr = [\n  { data: { year: '2016', tag: 'one', month: 'jan', day: '01'}, content: '...'},\n  { data: { year: '2016', tag: 'one', month: 'jan', day: '01'}, content: '...'},\n  { data: { year: '2016', tag: 'one', month: 'jan', day: '02'}, content: '...'},\n  { data: { year: '2016', tag: 'one', month: 'jan', day: '02'}, content: '...'},\n  { data: { year: '2016', tag: 'one', month: 'feb', day: '10'}, content: '...'},\n  { data: { year: '2016', tag: 'one', month: 'feb', day: '10'}, content: '...'},\n  { data: { year: '2016', tag: 'one', month: 'feb', day: '12'}, content: '...'},\n  { data: { year: '2016', tag: 'one', month: 'feb', day: '12'}, content: '...'},\n  { data: { year: '2016', tag: 'two', month: 'jan', day: '14'}, content: '...'},\n  { data: { year: '2016', tag: 'two', month: 'jan', day: '14'}, content: '...'},\n  { data: { year: '2016', tag: 'two', month: 'jan', day: '16'}, content: '...'},\n  { data: { year: '2016', tag: 'two', month: 'jan', day: '16'}, content: '...'},\n  { data: { year: '2016', tag: 'two', month: 'feb', day: '18'}, content: '...'},\n  { data: { year: '2017', tag: 'two', month: 'feb', day: '18'}, content: '...'},\n  { data: { year: '2017', tag: 'two', month: 'feb', day: '10'}, content: '...'},\n  { data: { year: '2017', tag: 'two', month: 'feb', day: '10'}, content: '...'},\n  { data: { year: '2017', tag: 'three', month: 'jan', day: '01'}, content: '...'},\n  { data: { year: '2017', tag: 'three', month: 'jan', day: '01'}, content: '...'},\n  { data: { year: '2017', tag: 'three', month: 'jan', day: '02'}, content: '...'},\n  { data: { year: '2017', tag: 'three', month: 'jan', day: '02'}, content: '...'},\n  { data: { year: '2017', tag: 'three', month: 'feb', day: '01'}, content: '...'},\n  { data: { year: '2017', tag: 'three', month: 'feb', day: '01'}, content: '...'},\n  { data: { year: '2017', tag: 'three', month: 'feb', day: '02'}, content: '...'},\n  { data: { year: '2017', tag: 'three', month: 'feb', day: '02'}, content: '...'}\n]\n```\n\nPass a list or array of properties:\n\n```js\ngroupArray(arr, 'data.year', 'data.tag', 'data.month', 'data.day');\n```\n\n**Results in something like this: (abbreviated)**\n\n```js\n{ '2016': \n   { one: \n      { jan: \n         { '01': \n            [ { data: { year: '2016', tag: 'one', month: 'jan', day: '01' },\n                content: '...' },\n              { data: { year: '2016', tag: 'one', month: 'jan', day: '01' },\n                content: '...' } ],\n           '02': \n            [ { data: { year: '2016', tag: 'one', month: 'jan', day: '02' },\n                content: '...' },\n              { data: { year: '2016', tag: 'one', month: 'jan', day: '02' },\n                content: '...' } ] },\n        feb: \n         { '10': \n            [ { data: { year: '2016', tag: 'one', month: 'feb', day: '10' },\n                content: '...' },\n              { data: { year: '2016', tag: 'one', month: 'feb', day: '10' },\n                content: '...' } ],\n           '12': \n            [ { data: { year: '2016', tag: 'one', month: 'feb', day: '12' },\n                content: '...' },\n              { data: { year: '2016', tag: 'one', month: 'feb', day: '12' },\n                content: '...' } ] } },\n     two: \n      { jan: \n         { '14': \n            [ { data: { year: '2016', tag: 'two', month: 'jan', day: '14' },\n                content: '...' },\n              { data: { year: '2016', tag: 'two', month: 'jan', day: '14' },\n                content: '...' } ],\n           '16': \n            [ { data: { year: '2016', tag: 'two', month: 'jan', day: '16' },\n                content: '...' },\n              { data: { year: '2016', tag: 'two', month: 'jan', day: '16' },\n                content: '...' } ] },\n        feb: \n         { '18': \n            [ { data: { year: '2016', tag: 'two', month: 'feb', day: '18' },\n                content: '...' } ] } } },\n  '2017': \n   { two: \n      { feb: \n         { '10': \n            [ { data: { year: '2017', tag: 'two', month: 'feb', day: '10' },\n                content: '...' },\n              { data: { year: '2017', tag: 'two', month: 'feb', day: '10' },\n                content: '...' } ],\n           '18': \n            [ { data: { year: '2017', tag: 'two', month: 'feb', day: '18' },\n                content: '...' } ] } },\n     three: \n      { jan: \n         { '01': \n            [ { data: { year: '2017', tag: 'three', month: 'jan', day: '01' },\n                content: '...' },\n              { data: { year: '2017', tag: 'three', month: 'jan', day: '01' },\n                content: '...' } ],\n           '02': \n            [ { data: { year: '2017', tag: 'three', month: 'jan', day: '02' },\n                content: '...' },\n              { data: { year: '2017', tag: 'three', month: 'jan', day: '02' },\n                content: '...' } ] },\n        feb: \n         { '01': \n            [ { data: { year: '2017', tag: 'three', month: 'feb', day: '01' },\n                content: '...' },\n              { data: { year: '2017', tag: 'three', month: 'feb', day: '01' },\n                content: '...' } ],\n           '02': \n            [ { data: { year: '2017', tag: 'three', month: 'feb', day: '02' },\n                content: '...' },\n              { data: { year: '2017', tag: 'three', month: 'feb', day: '02' },\n                content: '...' } ] } } } }\n```\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [arr-flatten](https://www.npmjs.com/package/arr-flatten): Recursively flatten an array or arrays. | [homepage](https://github.com/jonschlinkert/arr-flatten \"Recursively flatten an array or arrays.\")\n* [get-value](https://www.npmjs.com/package/get-value): Use property paths like 'a.b.c' to get a nested value from an object. Even works… [more](https://github.com/jonschlinkert/get-value) | [homepage](https://github.com/jonschlinkert/get-value \"Use property paths like 'a.b.c' to get a nested value from an object. Even works when keys have dots in them (no other dot-prop library can do this!).\")\n* [group-object](https://www.npmjs.com/package/group-object): Group object keys and values into lists. | [homepage](https://github.com/doowb/group-object \"Group object keys and values into lists.\")\n* [union-value](https://www.npmjs.com/package/union-value): Set an array of unique values as the property of an object. Supports setting deeply… [more](https://github.com/jonschlinkert/union-value) | [homepage](https://github.com/jonschlinkert/union-value \"Set an array of unique values as the property of an object. Supports setting deeply nested properties using using object-paths/dot notation.\")\n\n### Contributors\n\n| **Commits** | **Contributor** |  \n| --- | --- |  \n| 32 | [doowb](https://github.com/doowb) |  \n| 13 | [jonschlinkert](https://github.com/jonschlinkert) |  \n| 2  | [johlym](https://github.com/johlym) |  \n| 1  | [cperryk](https://github.com/cperryk) |  \n\n### Author\n\n**Brian Woodward**\n\n* [GitHub Profile](https://github.com/doowb)\n* [Twitter Profile](https://twitter.com/doowb)\n* [LinkedIn Profile](https://linkedin.com/in/woodwardbrian)\n\n### License\n\nCopyright © 2019, [Brian Woodward](https://github.com/doowb).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on July 22, 2019._","funding_links":[],"categories":["JavaScript","Modules","模块"],"sub_categories":["Array","数组"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fgroup-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoowb%2Fgroup-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fgroup-array/lists"}