{"id":18687296,"url":"https://github.com/junosuarez/indexed-array","last_synced_at":"2025-07-11T11:33:22.631Z","repository":{"id":57273424,"uuid":"6702066","full_name":"junosuarez/indexed-array","owner":"junosuarez","description":"An extension to native Array which supports direct element lookup by position index or primary key.","archived":false,"fork":false,"pushed_at":"2015-05-12T03:13:18.000Z","size":140,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-28T22:56:39.431Z","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/junosuarez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-15T09:05:42.000Z","updated_at":"2017-12-13T15:47:06.000Z","dependencies_parsed_at":"2022-09-17T02:23:05.603Z","dependency_job_id":null,"html_url":"https://github.com/junosuarez/indexed-array","commit_stats":null,"previous_names":["jden/indexed-array"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/junosuarez/indexed-array","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Findexed-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Findexed-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Findexed-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Findexed-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junosuarez","download_url":"https://codeload.github.com/junosuarez/indexed-array/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Findexed-array/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263733207,"owners_count":23503121,"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-11-07T10:32:20.927Z","updated_at":"2025-07-11T11:33:22.609Z","avatar_url":"https://github.com/junosuarez.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IndexedArray\n\nAn extension to native Array which supports direct element lookup by position index or primary key. Objects returned by IndexedArray are Array-like, meaning they have a `.length` property and are `instanceof Array`.\n\n## Usage\n\n    var IndexedArray = require('indexed-array')\n\n    var data = [\n      {_id: 'abc', name: 'Kurosawa'},\n      {_id: 'xyz', name: 'Gondry'},\n      {_id: 'rst', name: 'Almodovar'}\n    ];\n\n    var arr = IndexedArray(data)\n    arr['abc'].name; // 'Kurosawa'\n    arr[0].name;     // 'Kurosawa'\n    arr['rst'].name; // 'Almodovar'\n    arr[2].name;     // 'Almodovar'\n\nThe `IndexedArray` constructor takes an optional existing Array and an optional indexer, which can be either the name of the property to index or a function like you would pass to `Array.prototype.map`. By default, MongoDB style `_id` is used.\n\n    var arrByName = IndexedArray(data, 'name')\n    arrByName['Kurosawa']._id; // =\u003e 'abc'\n\n    var arrByName2 = IndexedArray(data, function (x) { return x.name.toLowerCase() })\n    arrByName2['almodovar']._id; // =\u003e 'rst'\n\nYou can also create an IndexedArray from an object being used as a hashmap:\n\n    var obj = {\n      'QWE': {val: 'qwe'},\n      'ASD': {val: 'asd'},\n      'ZXC': {val: 'zxc'}\n    }\n\n    var arr = IndexedArray.fromObject(obj)\n\nNow you can use Array-like methods, such as `push` and `pop` while still being able to access objects in O(1) time without iteration.\n\nWhen you're done mutating the IndexedArray, you can get the the hashmap directly:\n\n    arr.toObject()\n\n\nIndexedArray supports normal Array.prototype methods:\n\n - pop\n - push\n - shift\n - unshift\n - splice\n - slice\n\nSince IndexedArrays extend plain old Arrays, collection methods work great:\n\n - forEach\n - map\n - reduce\n - filter\n - some\n - every\n - sort\n\nAnd third party libraries should play nice, too, for example Lo-Dash or underscore.\n\nSee tests for more examples.\n\n## AMD Compatibility\n\nIndexedArray supports AMD modules and can be used either in node or in the browser. IndexedArray has no dependencies on node but may require ES5 shims in really old browsers.\n\n## Installation\n\n    $ npm install indexed-array\n\n## Running the tests\n\nFrom project root,\n\n    $ npm install\n    $ npm test\n\n## Contributing\nFeel free to open an issue or a pull request.\n\n## License\nCopyright (c) 2012 Jason Denizac \u003cjason@denizac.org\u003e\nLicensed under the MIT license.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunosuarez%2Findexed-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunosuarez%2Findexed-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunosuarez%2Findexed-array/lists"}