{"id":20601864,"url":"https://github.com/tomasfn87/sort-object-array-by-property","last_synced_at":"2026-05-06T04:03:56.390Z","repository":{"id":57131059,"uuid":"453242456","full_name":"tomasfn87/sort-object-array-by-property","owner":"tomasfn87","description":"Sorts an array of objects or an array of arrays according to a single property (objects) or index (arrays), or by multiple properties/indices, through an array of properties or indices. Also supports the selection of standard or reverse order to sort each set of values (or each \"column\").","archived":false,"fork":false,"pushed_at":"2023-12-24T10:38:21.000Z","size":130,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-04T21:32:20.352Z","etag":null,"topics":["accents","arrays","javascript","json","latin-language","npm","objects","properties","property","sort","typescript"],"latest_commit_sha":null,"homepage":"https://bit.ly/3DWopR9","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomasfn87.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-01-28T23:05:30.000Z","updated_at":"2023-12-15T19:00:12.000Z","dependencies_parsed_at":"2024-11-16T09:12:21.330Z","dependency_job_id":"3a40495c-264f-4d48-9b5a-64dcd88482ac","html_url":"https://github.com/tomasfn87/sort-object-array-by-property","commit_stats":{"total_commits":133,"total_committers":2,"mean_commits":66.5,"dds":0.03007518796992481,"last_synced_commit":"55c0183de1b2dd6c65ac302694f638b6573268a2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tomasfn87/sort-object-array-by-property","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasfn87%2Fsort-object-array-by-property","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasfn87%2Fsort-object-array-by-property/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasfn87%2Fsort-object-array-by-property/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasfn87%2Fsort-object-array-by-property/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomasfn87","download_url":"https://codeload.github.com/tomasfn87/sort-object-array-by-property/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasfn87%2Fsort-object-array-by-property/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32677933,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-06T02:33:58.958Z","status":"ssl_error","status_checked_at":"2026-05-06T02:33:39.611Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["accents","arrays","javascript","json","latin-language","npm","objects","properties","property","sort","typescript"],"created_at":"2024-11-16T09:12:16.718Z","updated_at":"2026-05-06T04:03:56.348Z","avatar_url":"https://github.com/tomasfn87.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sort-object-array-by-property\n\n\u003cbr\u003e\u003cbr\u003e\n\n## Table of contents\n\n- [Description](#description)\n- [Test it on a browser (`runkit.com`)](#test-with-runkit)\n- [Install](#install)\n- [Import](#import)\n  - [CommonJs](#import-cjs)\n  - [ES](#import-es)\n  - [TypeScript](#import-ts)\n- [Usage](#usage)\n  - [Single property](#usage-single-prop)\n  - [Multiple properties](#usage-multiple-props)\n  - [Nested properties](#usage-nested-props)\n  - [Reversing](#usage-reversal)\n- [Dealing with the output](#output)\n- [Examples](#examples)\n\n\u003cbr\u003e\u003cbr\u003e\n\n## \u003cspan id=\"description\"\u003eDescription\u003c/span\u003e\n\n`sort-object-array-by-property` _sorts an_ `array of objects` _or an_ `array of arrays` _according to a_ __single property__ (`objects`) _or_ __index__ (`arrays`)_, or by_ __multiple properties / indices__, through an __array of properties__ or __indices__, _including the_`length` _property_ (for `arrays` and `strings`).\n\n\u003cbr\u003e\n\n- It supports properties from `nested objects` and indices from `nested arrays`.\n\n- Each set of values (_the values that correspond to each property_) can be sorted independently, in `ascending` or `descending` order.\n\n- It supports sorting of texts with accents (`fiancée` _comes after_ `fiancee` _and before_ `fiancf`, _as a text editor would normally behave_), making it more useful for latin language users, for example.\n\n:warning: **Warning**: be aware that dealing with accentuation uses a lot of resources, so if you don't need to handle this problem, it's strongly recommended to use the previous version:\n\n```shell\nnpm install @nighly/sort-object-array-by-property@1.3.1\n```\n\n\u003cbr\u003e\u003cbr\u003e\n\n## \u003cspan id=\"test-with-runkit\"\u003e__Test it on a browser__ ([*__runkit__*](https://runkit.com/))\u003c/span\u003e\n\n[__sort-object-array-by-property__](https://runkit.com/tomasfn87/sort-object-array-by-property)\n\n---\n\n\u003cbr\u003e\u003cbr\u003e\n\n## \u003cspan id=\"install\"\u003e1) Install package via [`npm`](https://bit.ly/3DWopR9)\u003c/span\u003e\n\n```shell\n    npm install @nighly/sort-object-array-by-property\n```\n\n---\n\n\u003cbr\u003e\u003cbr\u003e\n\n## \u003cspan id=\"import\"\u003e2) Import package\u003c/span\u003e\n\n_Import function_ `sortObjectArrByProps` _by adding one of the lines below to a_ `Javascript` _or_ `Typescript` _file_:\n\n\u003cbr\u003e\n\n### \u003cspan id=\"import-cjs\"\u003e2.1) `CommonJs`\u003c/span\u003e\n\n#### _How to import_:\n\n```javascript\n    const sortObjs = require( '@nighly/sort-object-array-by-property' );\n```\n\n#### _How to call_:\n\n```javascript\n//  using a single property as sorting parameter:\n    sortObjs.sortObjectArrByProps( object_array, prop_1 );\n\n//  using three properties as sorting parameters:\n    sortObjs.sortObjectArrByProps( object_array, [ prop_1, prop_2, prop_3 ] );\n```\n\n\u003cbr\u003e\n\n#### 2.1.1) `CommonJs` _with_ destructuring (_shorter call_):\n\n##### _How to import_:\n\n```javascript\n    const { sortObjectArrByProps } = require( '@nighly/sort-object-array-by-property' );\n```\n\n##### _How to call_:\n\n```javascript\n//  using a single property as sorting parameter:\n    sortObjectArrByProps( object_array, prop_1 );\n\n//  using three properties as sorting parameters:\n    sortObjectArrByProps( object_array, [ prop_1, prop_2, prop_3 ] );\n```\n\n\u003cbr\u003e\u003cbr\u003e\n\n### \u003cspan id=\"import-es\"\u003e2.2) `ES`\u003c/span\u003e\n\n#### _How to import_:\n\n```javascript\n    import { sortObjectArrByProps } from '@nighly/sort-object-array-by-property/dist/sortObjArrByProps.js';\n```\n\n#### _How to call_:\n\n_Add_ `\"type\": \"module\"` _to_ `package.json` _or change the file extension from_ `.js` _to_ `.mjs`.\n\n```javascript\n//  using a single property as sorting parameter:\n    sortObjectArrByProps( object_array, prop_1 );\n\n//  using three properties as sorting parameters:\n    sortObjectArrByProps( object_array, [ prop_1, prop_2, prop_3 ] );\n```\n\n\u003cbr\u003e\u003cbr\u003e\n\n### \u003cspan id=\"import-ts\"\u003e2.3) `Typescript`\u003c/span\u003e\n\n#### _How to import_:\n\n```javascript\n    import { sortObjectArrByProps } from '@nighly/sort-object-array-by-property';\n```\n\n#### _How to call_:\n\n```javascript\n//  using a single property as sorting parameter:\n    sortObjectArrByProps( object_array, prop_1 );\n\n//  using three properties as sorting parameters:\n    sortObjectArrByProps( object_array, [ prop_1, prop_2, prop_3 ] );\n```\n\n---\n\n\u003cbr\u003e\u003cbr\u003e\n\n## \u003cspan id=\"usage\"\u003e3) Usage\u003c/span\u003e\n\n\u003cbr\u003e\n\n`sortObjectArrByProps` _sorts_ `objArr`, _an_ `array` _containing_ `objects` _or other_ `arrays` _according to_ `objProps` _value(s)_.\n\n\u003cbr\u003e\n\n```javascript\n//  using a single property as sorting parameter:\n    sortObjectArrByProps( objArr, objProps );\n\n//  using a single property, reversing as sorting parameter:\n    sortObjectArrByProps( objArr, objProps, reverse );\n\n//  using multiple properties as sorting parameter:\n    sortObjectArrByProps( objArr, [ ...objProps ] );\n\n//  using multiple properties, reversing as sorting parameter:\n    sortObjectArrByProps( objArr, [ ...objProps ], reverse );\n```\n\n\u003cbr\u003e\u003cbr\u003e\n\n_The_ `arrays` _can be sorted according to_:\n\n### \u003cspan id=\"usage-single-prop\"\u003e3.1) a _single property_\u003c/span\u003e\n\n```javascript\n//  an object's property\n    'name'  /* or */  'id'\n\n//  an array's index\n    0  /* or */  2\n```\n\n\u003cbr\u003e\n\n### \u003cspan id=\"usage-multiple-props\"\u003e3.2) _two_, _more_ or _all properties_\u003c/span\u003e\n\n```javascript\n//  an array of objects' properties\n    [ 'name', 'age' ]  /* or */  [ 'type', 'price' ]\n\n//  an array of arrays' indices\n    [0, 1]  /* or */  [2, 5]\n```\n\n\u003cbr\u003e\u003cbr\u003e\n\n### \u003cspan id=\"usage-nested-props\"\u003e3.3) _Using_ `nested objects' properties` _or_ `nested arrays' indices` _to sort_\u003c/span\u003e\n\n\u003cbr\u003e\n\n_To use_ `nested objects' properties` _or_ `nested arrays' indices`, _use the syntax below for_ `objProps`:\n\n```javascript\n    'a.b.c'  //  -\u003e  { a: { b: { c: 1 } } }  -\u003e  1\n    '0.0.0'  //  -\u003e      [ [ [ 2 ] ] ]       -\u003e  2\n```\n\n_Also works with combinations of_ `objects` _and_ `arrays`:\n\n```javascript\n    'a.0.b'  //  -\u003e   { a: [ { b: 3 } ] }    -\u003e  3\n    '0.a.0'  //  -\u003e    [ { a: [ 4 ] } ]      -\u003e  4\n```\n\n#### _Examples_:\n\n```javascript\n    sorbObjectArrByProps( objArr, 'a.b.c' );\n    sortObjectArrByProps( arrArr, '0.0.0' );\n```\n\n---\n\n\u003cbr\u003e\u003cbr\u003e\n\n### \u003cspan id=\"usage-reversal\"\u003e3.4) Reversing _all_ or _some values_\u003c/span\u003e\n\n_The third and optional parameter,_ `reverse`_, can receive as argument a_ `string`:\n- a single `r` (_or_ `R`) will reverse the whole list;\n- if only one set of values or some of the sets of values need to be reversed, a string with `length` greater than `1` containg `r` or `R` must be passed;\n- only a `r` or a `R` matters: any other character will just be used to determine which set of values will be reversed, according to the `properties` or `indices` passed in `array` format to `objProps`.\n\n\u003cbr\u003e\u003cbr\u003e\n\n#### _Examples_:\n\n```javascript\n//  the whole list will be reversed\n    sortObjectArrByProps( peopleArr, [ 'country', 'age', 'first_name' ], 'r' )\n```\n\n```javascript\n//  (            s           )(           r         )(              s             )\n//  by country standard order \u003e by age reverse order \u003e by first_name standard order\n    sortObjectArrByProps( peopleArr, [ 'country', 'age', 'first_name' ], 'srs' )\n```\n\n\u003cbr\u003e\u003cbr\u003e\n\n#### 3.4.1) `reverse` alternative notations:\n\n_As aforementioned_ (__3.4__), _while_ `s` _is the standard notation_, _any string value different from_ `r` _or_ `R` _will be accepted_:\n\n```javascript\n//  (            r          )(               .            )(            .           )\n//  by year descending order \u003e by platform ascending order \u003e by title ascending order\n    sortObjectArrByProps( gamesArr, [ 'year', 'platform', 'title' ], 'r..' )\n```\n\n\u003cbr\u003e\n\n_Similarly, the snippet below_ ...\n\n```javascript\n    sortObjectArrByProps( objList, [ 'prop1', 'prop2' ], 's' );\n//  or\n    sortObjectArrByProps( arrList, [ 1, 2 ], 's' );\n```\n\n```javascript\n    sortObjectArrByProps( objList, [ 'prop1', 'prop2' ] );\n//  or\n    sortObjectArrByProps( arrList, [ 1, 2 ] );\n```\n\n... _produces the same output as the snippet above_.\n\n---\n\n\u003cbr\u003e\u003cbr\u003e\n\n### \u003cspan id=\"output\"\u003e4) Dealing with the _output_\u003c/span\u003e\n\n`sortObjectArrByProps` _returns a_ `new array`, _leaving the_ `source array` _untouched_, _so reattribute the ouput to the same variable to update the values_, _or attribute it to a new variable_, _to store the values_:\n\n\u003cbr\u003e\n\n#### _Updating_:\n\n```javascript\n    usersList = sortObjectArrByProps(         // \u003c- the variable IS NOT being declared;\n        usersList, [                          // \u003c- the list to be sorted IS the same variable that will store the result;\n            'birth_date',                     // \u003c- 1st order by, then;\n            'last_name',                      // \u003c- 2nd order by, then;\n            'first_name',                     // \u003c- 3rd order by, then;\n            'email',                          // \u003c- 4th order by, end;\n        ], '..R'                              // \u003c- reverse string.\n    );\n```\n\n#### _Storing_:\n\n```javascript\n    let sortedList = sortObjectArrByProps(    // \u003c- the variable IS being declared;\n        list, [                               // \u003c- the list to be sorted IS NOT the same variable that will store the result;\n            'date.year',                      // \u003c- 1st order by, then;\n            'date.month',                     // \u003c- 2nd order by, then;\n            'date.day',                       // \u003c- 3rd order by, then;\n            'date.time',                      // \u003c- 4th order by, then;\n            'id'                              // \u003c- 5th order by, end;\n       ], 'RrRr.'                             // \u003c- reverse string.\n    );\n```\n\n---\n\n\u003cbr\u003e\u003cbr\u003e\n\n## \u003cspan id=\"examples\"\u003e5) _Examples_\u003c/span\u003e\n\n\u003cbr\u003e\n\n_The comments represent the_ *__outputs__*:\n\n```javascript\nsortObjectArrByProps([\n  [ 4, 2 ],                             // -\u003e    [ 1, 4 ],\n  [ 3, 5 ],                             // -\u003e    [ 2, 3 ],\n  [ 1, 4 ],                             // -\u003e    [ 3, 5 ],\n  [ 5, 1 ],                             // -\u003e    [ 4, 2 ],\n  [ 2, 3 ]                              // -\u003e    [ 5, 1 ]\n], 0 );\n\nsortObjectArrByProps([\n  [ 4, 2 ],                             // -\u003e    [ 5, 1 ],\n  [ 3, 5 ],                             // -\u003e    [ 4, 2 ],\n  [ 1, 4 ],                             // -\u003e    [ 3, 5 ],\n  [ 5, 1 ],                             // -\u003e    [ 2, 3 ],\n  [ 2, 3 ]                              // -\u003e    [ 1, 4 ]\n], 0, 'r' );\n\nsortObjectArrByProps([\n  { a: 4, b: 2 },                       // -\u003e    { a: 5, b: 1 },\n  { a: 3, b: 5 },                       // -\u003e    { a: 4, b: 2 },\n  { a: 1, b: 4 },                       // -\u003e    { a: 2, b: 3 },\n  { a: 5, b: 1 },                       // -\u003e    { a: 1, b: 4 },\n  { a: 2, b: 3 }                        // -\u003e    { a: 3, b: 5 }\n], 'b' );\n\nsortObjectArrByProps([\n  { a: 4, b: 2 },                       // -\u003e    { a: 3, b: 5 },\n  { a: 3, b: 5 },                       // -\u003e    { a: 1, b: 4 },\n  { a: 1, b: 4 },                       // -\u003e    { a: 2, b: 3 },\n  { a: 5, b: 1 },                       // -\u003e    { a: 4, b: 2 },\n  { a: 2, b: 3 }                        // -\u003e    { a: 5, b: 1 }\n], 'b', 'r' );\n\nsortObjectArrByProps([\n  { a: 1, b: 2 },                       // -\u003e    { a: 1, b: 1 },\n  { a: 2, b: 2 },                       // -\u003e    { a: 1, b: 2 },\n  { a: 2, b: 1 },                       // -\u003e    { a: 2, b: 1 },\n  { a: 1, b: 1 },                       // -\u003e    { a: 2, b: 2 },\n  { a: 3, b: 3 }                        // -\u003e    { a: 3, b: 3 }\n], [ 'a', 'b' ] );\n\nsortObjectArrByProps([\n  { a: 1, b: 2 },                       // -\u003e    { a: 3, b: 3 },\n  { a: 2, b: 2 },                       // -\u003e    { a: 2, b: 2 },\n  { a: 2, b: 1 },                       // -\u003e    { a: 2, b: 1 },\n  { a: 1, b: 1 },                       // -\u003e    { a: 1, b: 2 },\n  { a: 3, b: 3 }                        // -\u003e    { a: 1, b: 1 }\n], [ 'a', 'b' ], 'r' );\n\nsortObjectArrByProps([\n  { a: 1, b: 2 },                       // -\u003e    { a: 1, b: 1 },\n  { a: 2, b: 2 },                       // -\u003e    { a: 2, b: 1 },\n  { a: 2, b: 1 },                       // -\u003e    { a: 1, b: 2 },\n  { a: 1, b: 1 },                       // -\u003e    { a: 2, b: 2 },\n  { a: 3, b: 3 }                        // -\u003e    { a: 3, b: 3 }\n], [ 'b', 'a' ] );\n\nsortObjectArrByProps([\n  { a: 1, b: 2 },                       // -\u003e    { a: 3, b: 3 },\n  { a: 2, b: 2 },                       // -\u003e    { a: 2, b: 2 },\n  { a: 2, b: 1 },                       // -\u003e    { a: 1, b: 2 },\n  { a: 1, b: 1 },                       // -\u003e    { a: 2, b: 1 },\n  { a: 3, b: 3 }                        // -\u003e    { a: 1, b: 1 }\n], [ 'b', 'a' ], 'r' );\n\nsortObjectArrByProps([\n  { c: '2', d: 5 },                     // -\u003e     { a: { b: false }, c: '2', d: 5 },\n  { a: { b: true }, c: '11', d: 11 },   // -\u003e     { a: { b: false }, c: '20', d: 3 },\n  { a: { b: false }, c: '3', d: 10 },   // -\u003e     { a: { b: false }, c: '3', d: 10 },\n  { a: { b: true }, c: '11', d: 6 },    // -\u003e     { a: { b: true }, c: '11', d: 6 },\n  { a: { b: false }, c: '20', d: 3 },   // -\u003e     { a: { b: true }, c: '11', d: 11 },\n  { a: { b: false }, c: '2', d: 5 },    // -\u003e     { c: '2', d: 5 },\n  { c: '2', d: 10 }                     // -\u003e     { c: '2', d: 10 }\n], [ 'a.b', 'c', 'd' ] );\n\nsortObjectArrByProps([\n  { c: '2', d: 5 },                     // -\u003e     { a: { b: false }, c: '3', d: 10 },\n  { a: { b: true }, c: '11', d: 11 },   // -\u003e     { a: { b: false }, c: '20', d: 3 },\n  { a: { b: false }, c: '3', d: 10 },   // -\u003e     { a: { b: false }, c: '2', d: 5 },\n  { a: { b: true }, c: '11', d: 6 },    // -\u003e     { a: { b: true }, c: '11', d: 11 },\n  { a: { b: false }, c: '20', d: 3 },   // -\u003e     { a: { b: true }, c: '11', d: 6 },\n  { a: { b: false }, c: '2', d: 5 },    // -\u003e     { c: '2', d: 10 },\n  { c: '2', d: 10 }                     // -\u003e     { c: '2', d: 5 }\n], [ 'a.b', 'c', 'd' ], '.rr' );\n\nsortObjectArrByProps([\n  [[],[],[],[],[]],                     // -\u003e     [[]],\n  [[]],                                 // -\u003e     [[],[]],\n  [[],[],[],[],[],[]],                  // -\u003e     [[],[],[]],\n  [[],[],[]],                           // -\u003e     [[],[],[],[]],\n  [[],[]],                              // -\u003e     [[],[],[],[],[]],\n  [[],[],[],[]]                         // -\u003e     [[],[],[],[],[],[]]\n], 'length' );\n\nsortObjectArrByProps([\n  [[],[],[],[],[]],                     // -\u003e     [[],[],[],[],[],[]],\n  [[]],                                 // -\u003e     [[],[],[],[],[]],\n  [[],[],[],[],[],[]],                  // -\u003e     [[],[],[],[]],\n  [[],[],[]],                           // -\u003e     [[],[],[]],\n  [[],[]],                              // -\u003e     [[],[]],\n  [[],[],[],[]]                         // -\u003e     [[]]\n], 'length', 'r' );\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasfn87%2Fsort-object-array-by-property","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomasfn87%2Fsort-object-array-by-property","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasfn87%2Fsort-object-array-by-property/lists"}