{"id":19041955,"url":"https://github.com/writetome51/get-grouped-by-property","last_synced_at":"2026-05-13T20:31:58.566Z","repository":{"id":122062405,"uuid":"170058338","full_name":"writetome51/get-grouped-by-property","owner":"writetome51","description":"Returns array of objects divided into sub-arrays, grouped by value of a particular property","archived":false,"fork":false,"pushed_at":"2021-05-12T18:19:51.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-09T00:35:48.437Z","etag":null,"topics":["grouping","javascript","object","objects","sort","sorting"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/writetome51.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":"2019-02-11T02:55:05.000Z","updated_at":"2021-05-12T18:19:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"81093ef8-0aae-4618-b933-c90004f27073","html_url":"https://github.com/writetome51/get-grouped-by-property","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/writetome51/get-grouped-by-property","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-grouped-by-property","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-grouped-by-property/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-grouped-by-property/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-grouped-by-property/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/writetome51","download_url":"https://codeload.github.com/writetome51/get-grouped-by-property/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-grouped-by-property/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32999212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"ssl_error","status_checked_at":"2026-05-13T13:14:51.610Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["grouping","javascript","object","objects","sort","sorting"],"created_at":"2024-11-08T22:33:29.883Z","updated_at":"2026-05-13T20:31:58.547Z","avatar_url":"https://github.com/writetome51.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# getGroupedByProperty\\\u003cT\\\u003e(\u003cbr\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;property: string,\u003cbr\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;objects: T[],\u003cbr\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;matchFound? = (a, b) =\u003e String(a) === String(b)\u003cbr\u003e): Array\u003cT[]\u003e\n\nReturns `objects` divided into sub-arrays, grouped by matching value of `property`.  \nThe original `objects` array is not modified.  \nYou can customize how a match is determined with optional callback `matchFound(a, b)`  \n(by default it returns `String(a) === String(b)` ).  \nBased on the data type of `objects[0][property]`, this function decides how to sort  \nall `objects`. That type must be either number (sorting will be numeric), string or  \nboolean (sorting will be alphabetical for both). After sorting, adjacent objects are  \ngrouped together if `matchFound(a, b)` returns true.\n\nNote: `property` is a string that can include dot-notation ( i.e.,  \n`'property.subproperty.subsubproperty'` ).  Even if `property` is an array index,  \nhere you need to use dot-notation and not square braces, i.e., `'1.0' // instead of [1][0]`  \n\n## Examples\n```js\npersons = [\n\t{person: {hair: 'red', name: 'tom'}},\n\t{person: {hair: 'brown', name: 'ron'}},\n\t{person: {hair: 'black', name: 'harry'}},\n\t{person: {hair: 'blue', name: 'barry'}},\n\t{person: {hair: 'brown', name: 'midge'}},\n\t{person: {hair: 'black', name: 'sandy'}}\n];\ngetGroupedByProperty('person.hair', persons);\n/*************\nReturns:\n[\n   [ {person: {hair: 'black', name: 'harry'}}, {person: {hair: 'black', name: 'sandy'}} ],\n   [ {person: {hair: 'blue', name: 'barry'}} ],\n   [ {person: {hair: 'brown', name: 'ron'}}, {person: {hair: 'brown', name: 'midge'}} ],\n   [ {person: {hair: 'red', name: 'tom'}} ]\n]\n*************/\n\n\n// If any values are null or undefined, they will be treated as if they\n// were strings 'null' and 'undefined':\n\npersons = [\n\t{person: {hair: 'red', name: 'tom'}},\n\t{person: {hair: 'null', name: 'ron'}},\n\t{person: {name: 'harry'}}, // missing property means its value is undefined.\n\t{person: {hair: null, name: 'midge'}},\n\t{person: {hair: undefined, name: 'sandy'}}\n];\ngetGroupedByProperty('person.hair', persons);\n/*************\nReturns:\n[\n   [ {person: {hair: 'null', name: 'ron'}}, {person: {hair: null, name: 'midge'}} ],\n   [ {person: {hair: 'red', name: 'tom'}} ],\n   [ {person: {name: 'harry'}}, {person: {hair: undefined, name: 'sandy'}} ]\n]\n*************/\n\n\n// group together arrays with the same number of items:\n\nlet arrays = [\n    [1, 2], [3, 4, 5, 6, 7], [8, 9, 10], [11, 12], \n    [13, 14, 15, 16], [17, 18, 19, 20, 21], [22, 23, 24, 25]\n];\ngetGroupedByProperty('length', arrays);\n/*************\nReturns:\n[\n   [ [1, 2], [11, 12] ],\n   [ [8, 9, 10] ],\n   [ [13, 14, 15, 16], [22, 23, 24, 25] ],\n   [ [3, 4, 5, 6, 7], [17, 18, 19, 20, 21] ]\n]\n*************/\n\n\n// By default, matching is case-sensitive:\n\nobjs = [{prop: 'V'}, {prop: 'v'}, {prop: 'V'}, {prop: 'A'}, {prop: 'a'}, {prop: 'a'}];\ngetGroupedByProperty('prop', objs);\n/*************\nReturns:\n[\n   [ { prop: 'A' } ],\n   [ { prop: 'a' }, { prop: 'a' } ],\n   [ { prop: 'V' }, { prop: 'V' } ],\n   [ { prop: 'v' } ]\n]\n *************/\n\n// Make matching case-insensitive:\nobjs = [{prop: 'V'}, {prop: 'v'}, {prop: 'V'}, {prop: 'A'}, {prop: 'a'}, {prop: 'a'}];\ngetGroupedByProperty(\n    'prop', objs, (a, b) =\u003e String(a).toLowerCase() === String(b).toLowerCase()\n);\n/************\nReturns:\n[\n  [ { prop: 'A' }, { prop: 'a' }, { prop: 'a' } ],\n  [ { prop: 'V' }, { prop: 'V' }, { prop: 'v' } ]\n]\n*************/\n\n\n// These last 2 examples show the different ordering of results based on what object\n// comes first in the array.\n\n// Since the value of objs[0]['prop'] is a number, groups will be ordered\n// numerically:\nobjs = [{prop: 1}, {prop: '1.0001'}, {prop: '2.0'}, {prop: '1'}, \n        {prop: '00100'}, {prop: '03'}];\ngetGroupedByProperty('prop', objs);\n/***************\nReturns:\n[\n   [ { prop: 1 }, { prop: '1' } ],\n   [ { prop: '1.0001' } ],\n   [ { prop: '2.0' } ],\n   [ { prop: '03' } ],\n   [ { prop: '00100' } ]\n]\n***************/\n\n// Since the value of objs[0]['prop'] is a string, groups will be ordered\n// alphabetically:\nobjs = [{prop: '1.0001'}, {prop: 1}, {prop: '2.0'}, {prop: '1'}, \n        {prop: '00100'}, {prop: '03'}];\ngetGroupedByProperty('prop', objs);\n/***************\nReturns:\n[\n   [ { prop: '00100' } ],\n   [ { prop: '03' } ],\n   [ { prop: 1 }, { prop: '1' } ],\n   [ { prop: '1.0001' } ],\n   [ { prop: '2.0' } ]\n]\n***************/\n```\n\n## Installation\n\n```bash\nnpm i @writetome51/get-grouped-by-property\n```\n## Loading\n```js\nimport {getGroupedByProperty} from '@writetome51/get-grouped-by-property';\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwritetome51%2Fget-grouped-by-property","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwritetome51%2Fget-grouped-by-property","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwritetome51%2Fget-grouped-by-property/lists"}