{"id":19041957,"url":"https://github.com/writetome51/get-grouped-by-properties","last_synced_at":"2026-04-28T01:31:37.798Z","repository":{"id":122062414,"uuid":"170393209","full_name":"writetome51/get-grouped-by-properties","owner":"writetome51","description":"Separates array of objects into sub-arrays of objects with matching property values","archived":false,"fork":false,"pushed_at":"2021-11-17T22:21:12.000Z","size":46,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-23T06:27:23.624Z","etag":null,"topics":["array","grouping","javascript","object-sort","objects","sorting","typescript"],"latest_commit_sha":null,"homepage":"","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-12T21:20:36.000Z","updated_at":"2021-11-17T22:21:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"40287dfb-1922-4f95-b41b-48d3602a49ee","html_url":"https://github.com/writetome51/get-grouped-by-properties","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/writetome51/get-grouped-by-properties","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-grouped-by-properties","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-grouped-by-properties/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-grouped-by-properties/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-grouped-by-properties/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/writetome51","download_url":"https://codeload.github.com/writetome51/get-grouped-by-properties/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/writetome51%2Fget-grouped-by-properties/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261832679,"owners_count":23216497,"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","grouping","javascript","object-sort","objects","sorting","typescript"],"created_at":"2024-11-08T22:33:30.963Z","updated_at":"2026-04-28T01:31:32.778Z","avatar_url":"https://github.com/writetome51.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# getGroupedByProperties\\\u003cT\\\u003e(\u003cbr\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;properties: string[],\u003cbr\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;objects: T[],\u003cbr\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;matchFunctions?: {\u003cbr\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;[property: string]: (a, b) =\u003e boolean\u003cbr\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;}\u003cbr\u003e): Array\u003cT[]\u003e\n\nReturns `objects` separated into groups (sub-arrays).  Each group will contain objects with  \nmatching values of every property in `properties`.  You can customize how a match is determined  \nwith the optional `matchFunctions`.  \n\n`matchFunctions`: object. Any of its keys must be identical to a property in `properties`.  \nThe value of each key must be this type of function:  `(a, b) =\u003e boolean` . It's called to  \ndetermine a match when grouping by the property matching that particular key. If a matching key  \nisn't provided for a particular property, the default matchFunction  \n`(a, b) =\u003e String(a) === String(b)` will be used for that property.  \nYou can change the default matchFunction with the key `'$default'`.\n\nThe `properties` can each contain dot-notation, i.e, `'property.subproperty.subsubproperty'`.  \nEven if a property is an array index, here you need to use dot-notation and not  \nsquare braces, i.e. `'1.0' // instead of [1][0]`  \nThe order you list the `properties` determines the order the groups are returned in. \n\n\n## Examples\n```js\nlet persons = [\n\t{name: {first: 'Danny', last: 'Jones'}, address:'800 N. First St.'},\n\t{name: {first: 'Michael', last: 'Watts'}, address:'100 S. Palm Way'},\n\t{name: {first: 'Robert', last: 'Walters'}, address:'200 W. Elm St.'},\n\t{name: {first: 'Sara', last: 'Watts'}, address:'100 S. Palm Way'},\n\t{name: {first: 'Carol', last: 'Jones'}, address:'800 N. First St.'},\n\t{name: {first: 'Tara', last: 'Zucko'}, address:'100 S. Palm Way'},\n];\ngetGroupedByProperties(['address', 'name.last'], persons);\n/******************\nReturns:\n [\n    [\n       {name: {first: 'Michael', last: 'Watts'}, address: '100 S. Palm Way'},\n       {name: {first: 'Sara', last: 'Watts'}, address: '100 S. Palm Way'}\n    ],\n    [ {name: {first: 'Tara', last: 'Zucko'}, address:'100 S. Palm Way'} ],\n    [ {name: {first: 'Robert', last: 'Walters'}, address: '200 W. Elm St.'} ],\n    [\n       {name: {first: 'Danny', last: 'Jones'}, address: '800 N. First St.'},\n       {name: {first: 'Carol', last: 'Jones'}, address: '800 N. First St.'}\n    ]\n ]\n ******************/\n\n\n// Reverse the order of properties to see the result:\n\ngetGroupedByProperties(['name.last', 'address'], persons);\n/******************\nReturns:\n [\n    [\n       {name: {first: 'Danny', last: 'Jones'}, address: '800 N. First St.'},\n       {name: {first: 'Carol', last: 'Jones'}, address: '800 N. First St.'}\n    ],\n    [ {name: {first: 'Robert', last: 'Walters'}, address: '200 W. Elm St.'} ],\n    [\n       {name: {first: 'Michael', last: 'Watts'}, address: '100 S. Palm Way'},\n       {name: {first: 'Sara', last: 'Watts'}, address: '100 S. Palm Way'}\n    ],\n    [ {name: {first: 'Tara', last: 'Zucko'}, address:'100 S. Palm Way'} ]\n ]\n ******************/\n \n\n// This example makes matching case-insensitive by default:\n\npersons = [\n    { name: { first: 'Danny', last: 'Jones' }, email: 'd_jonesy500@yahoo.com' },\n    { name: { first: 'michael', last: 'watts' }, email: 'watts_my_name@gmail.com'},\n    { name: { first: 'Michael', last: 'Watts' }, email: 'watts_my_name@gmail.com' },\n    { name: { first: 'danny', last: 'jones' }, email: 'd_jonesy500@yahoo.com' }\n];\ngetGroupedByProperties(\n    ['name.last', 'email'],\n    persons,\n    {'$default': (a, b) =\u003e a.toLowerCase() === b.toLowerCase()} \n);\n/***************\nReturns:\n[\n  [\n    { name: { first: 'Danny', last: 'Jones' }, email: 'd_jonesy500@yahoo.com' },\n    { name: { first: 'danny', last: 'jones' }, email: 'd_jonesy500@yahoo.com' }\n  ],\n  [\n    { name: { first: 'Michael', last: 'Watts' }, email: 'watts_my_name@gmail.com' },\n    { name: { first: 'michael', last: 'watts' }, email: 'watts_my_name@gmail.com' }\n  ]\n]\n ****************/\n\n\n// This makes string matching case-insensitive and separates those younger than 100 \n// from those 100 and older:\n\npersons = [\n\t{name: {first: 'Eddie'}, age: 102},\n\t{name: {first: 'Eddie'}, age: 32},\n\t{name: {first: 'danny'}, age: 102},\n\t{name: {first: 'eric'}, age: 25},\n\t{name: {first: 'Danny'}, age: 31},\n\t{name: {first: 'David'}, age: 100},\n];\ngetGroupedByProperties(\n    // group by first letter of first name, and age:\n    ['name.first.0', 'age'],\n    persons,\n    {\n        'name.first.0': (a, b) =\u003e a.toLowerCase() === b.toLowerCase(),\n        // Separate ages between those younger than 100, and everyone else:\n        'age': (a, b) =\u003e a \u003c 100 ? b \u003c 100 : b \u003e= 100\n    }\n);\n/***********\nReturns:\n[\n  [ {name: {first: 'Danny'}, age: 31} ],\n  [ {name: {first: 'David'}, age: 100},  {name: {first: 'danny'}, age: 102} ],\n  [ {name: {first: 'eric'}, age: 25},  {name: {first: 'Eddie'}, age: 32} ],\n  [ {name: {first: 'Eddie'}, age: 102} ]\n]\n***********/\n```\n\n## Installation\n```bash\nnpm i @writetome51/get-grouped-by-properties\n```\n## Loading\n```js\nimport {getGroupedByProperties} from '@writetome51/get-grouped-by-properties';\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwritetome51%2Fget-grouped-by-properties","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwritetome51%2Fget-grouped-by-properties","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwritetome51%2Fget-grouped-by-properties/lists"}