{"id":21177546,"url":"https://github.com/grjan7/group-objects-array","last_synced_at":"2026-05-06T19:04:01.212Z","repository":{"id":38392130,"uuid":"506583834","full_name":"grjan7/group-objects-array","owner":"grjan7","description":"Groups JavaScript objects array by a key and returns grouped array. ","archived":false,"fork":false,"pushed_at":"2022-10-13T08:36:34.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-21T14:16:49.348Z","etag":null,"topics":["array","group","javascript","json","key-value","mql","nodejs","npm","npm-package","objects"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grjan7.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}},"created_at":"2022-06-23T09:51:35.000Z","updated_at":"2023-02-27T07:36:58.000Z","dependencies_parsed_at":"2023-01-19T15:18:01.973Z","dependency_job_id":null,"html_url":"https://github.com/grjan7/group-objects-array","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grjan7%2Fgroup-objects-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grjan7%2Fgroup-objects-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grjan7%2Fgroup-objects-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grjan7%2Fgroup-objects-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grjan7","download_url":"https://codeload.github.com/grjan7/group-objects-array/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243624857,"owners_count":20321181,"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":["array","group","javascript","json","key-value","mql","nodejs","npm","npm-package","objects"],"created_at":"2024-11-20T17:16:25.431Z","updated_at":"2026-05-06T19:04:01.166Z","avatar_url":"https://github.com/grjan7.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# group-objects-array\n\n[![NPM version](https://img.shields.io/npm/v/group-objects-array.svg)](https://www.npmjs.com/package/group-objects-array)\n[![NPM downloads](https://img.shields.io/npm/dm/group-objects-array.svg)](https://www.npmjs.com/package/group-objects-array)\n[![Known Vulnerabilities](https://snyk.io/test/github/grjan7/group-objects-array/badge.svg)](https://snyk.io/test/github/grjan7/group-objects-array)\n\n## Description\n\n  \u003e Groups JavaScript objects array by a key and returns grouped array.\n\n  \u003e Groups the scattered objects in an array based on a `groupByKey` (e.g. id). For the given `groupByKey` value, if there is a multiple occurrence of same key (e.g., contact key for id: 3) but with unique values, then the values will be grouped into an array.\n\n## Installation\n\n```sh\n\n  npm i group-objects-array\n\n```\n\n## Usage\n\n### `groupObjectArrayByKey(objArr, groupByKey)`\n\n- **objArr** an array of objects to be grouped\n- **groupByKey** an object key to group the objects\n\n```js\n\n const { groupObjectArrayByKey } = require('group-objects-array');\n \n const objArray = [\n   { id: 1, name: \"John\" },\n   { id: 2, name: \"Aaron\" },\n   { id: 1, age: 20 },\n   { id: 2, age: 30 },\n   { id: 3, name: \"Michel\" },\n   { id: 1, address: { street: \"123 Main Street\", city: \"NY\", country: \"USA\" } },\n   { id: 3, contact: \"+01-51245 53125\" },\n   { id: 3, contact: \"+02-51245 53125\" },\n   { id: 1, address: { street: \"123 Main Street\", city: \"NY\", country: \"USA\" } }  \n ];\n  \n groupObjectArrayByKey(objArray, \"id\");\n \n ```\n\n returns\n\n ```js\n [\n   {\n     id: 1, \n     name: \"John\", \n     age: 20, \n     address: { street: \"123 Main Street\", city: \"NY\", country: \"USA\" }\n   },\n   {\n     id: 2,\n     name: \"Aaron\",\n     age: 30\n   },\n   {\n     id: 3,\n     name: \"Michel\",\n     contact: [ \"+01-51245 53125\", \"+02-51245 53125\" ]\n   } \n ]\n\n ```\n\n### `uniqueArray(arr)`\n\nThis function returns an array with duplicates removed.\n\n- **arr** an array to be deduplicated to have only unique values\n\n```js\n\nconst { uniqueArray } = require(\"group-objects-array\");\n\nconst arr = [\n  { name: \"John\", age: 30 },\n  { name: \"Doe\", age: 29 },\n  { name: \"John\", age: 30 },\n  { name: \"Michel\", age: 21 }\n];\n\nuniqueArray(arr);\n\n```\n\nreturns\n\n```js\n\n[\n  { name: \"John\", age: 30 },\n  { name: \"Doe\", age: 29 },\n  { name: \"Michel\", age: 21 }\n]\n\n```\n\n### `isItemInArray(arr, item)`\n\nThis function checks if an item is in the given array.\n\n- **arr** source array\n- **item** item to be checked whether it is in the array  \n\n```js\n\nconst { isItemInArray } = require(\"group-objects-array\");\n\nconst arr = [ { name: \"John\" }, \"world\" ];\n\nisItemInArray(arr, { name: \"John\" }); // returns true\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrjan7%2Fgroup-objects-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrjan7%2Fgroup-objects-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrjan7%2Fgroup-objects-array/lists"}