{"id":15413485,"url":"https://github.com/wooorm/array-iterate","last_synced_at":"2025-04-19T11:39:59.029Z","repository":{"id":23190446,"uuid":"26546790","full_name":"wooorm/array-iterate","owner":"wooorm","description":"`Array#forEach()` but it’s possible to define where to move to next","archived":false,"fork":false,"pushed_at":"2022-11-20T13:22:33.000Z","size":79,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-12T18:53:23.578Z","etag":null,"topics":["array","iterate","list","walk"],"latest_commit_sha":null,"homepage":"","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/wooorm.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":"funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"wooorm"}},"created_at":"2014-11-12T17:09:50.000Z","updated_at":"2024-04-02T17:41:43.000Z","dependencies_parsed_at":"2022-08-30T05:40:56.200Z","dependency_job_id":null,"html_url":"https://github.com/wooorm/array-iterate","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Farray-iterate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Farray-iterate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Farray-iterate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Farray-iterate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wooorm","download_url":"https://codeload.github.com/wooorm/array-iterate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249685273,"owners_count":21310576,"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","iterate","list","walk"],"created_at":"2024-10-01T16:57:18.892Z","updated_at":"2025-04-19T11:39:58.998Z","avatar_url":"https://github.com/wooorm.png","language":"JavaScript","funding_links":["https://github.com/sponsors/wooorm"],"categories":[],"sub_categories":[],"readme":"# array-iterate\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n\n[`Array#forEach()`][foreach] but it’s possible to define where to move to next.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`arrayIterate(values, callbackFn[, thisArg])`](#arrayiteratevalues-callbackfn-thisarg)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nA tiny package that works just like `forEach`, with one small difference.\n\n## When should I use this?\n\nYou can use this if for some weird reason—like I did—you have to sometimes\nskip a few places ahead or backwards when moving through an array.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 14.14+, 16.0+), install with [npm][]:\n\n```sh\nnpm install array-iterate\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {arrayIterate} from 'https://esm.sh/array-iterate@2'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {arrayIterate} from 'https://esm.sh/array-iterate@2?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {arrayIterate} from 'array-iterate'\n\nlet first = true\n\narrayIterate(\n  [1, 2, 3, 4],\n  function (value, index, values){\n    console.log(this, value, index, values)\n\n    // Repeat once.\n    if (first \u0026\u0026 index + 1 === values.length) {\n      first = false\n      return 0\n    }\n  },\n  {hello: 'world'}\n)\n```\n\nYields:\n\n```js\n{hello: 'world'}, 1, 0, [1, 2, 3, 4]\n{hello: 'world'}, 2, 1, [1, 2, 3, 4]\n{hello: 'world'}, 3, 2, [1, 2, 3, 4]\n{hello: 'world'}, 4, 3, [1, 2, 3, 4]\n{hello: 'world'}, 1, 0, [1, 2, 3, 4]\n{hello: 'world'}, 2, 1, [1, 2, 3, 4]\n{hello: 'world'}, 3, 2, [1, 2, 3, 4]\n{hello: 'world'}, 4, 3, [1, 2, 3, 4]\n```\n\n## API\n\nThis package exports the identifier `arrayIterate`.\nThere is no default export.\n\n### `arrayIterate(values, callbackFn[, thisArg])`\n\nPerform the specified action for each element in an array (just like\n[`Array#forEach()`][foreach]).\nWhen `callbackFn` returns a `number`, moves to the element at that index\nnext.\n\n###### Parameters\n\n*   `values` (`Array\u003c*\u003e`)\n    — values to iterate over\n*   `callbackFn` (`Function`)\n    — function called for each element, can return the `index` to move to next\n*   `thisArg` (`*`, optional)\n    — optional object passed as `this` in `callbackFn`\n\n###### Returns\n\n`undefined`.\n\n#### `function callbackFn(value, index, values)`\n\nCallback given to `iterate`.\n\n###### Parameters\n\n*   `this` (`*`)\n    — context object when given as `thisArg` to `arrayIterate` or `undefined`\n*   `value` (`*`)\n    — element in array\n*   `index` (`number`)\n    — index of `value` in `values`\n*   `values` (`Array.\u003c*\u003e`)\n    — list\n\n###### Returns\n\nThe optional `index` to move to next (`number` or `undefined`)\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional type `CallbackFn`.\n\n## Compatibility\n\nThis package is at least compatible with all maintained versions of Node.js.\nAs of now, that is Node.js 14.14+ and 16.0+.\nIt also works in Deno and modern browsers.\n\n## Security\n\nThis package is safe, assuming that you don’t create an infinite loop\nby keeping on repeating.\n\n## Contribute\n\nYes please!\nSee [How to Contribute to Open Source][contribute].\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/wooorm/array-iterate/workflows/main/badge.svg\n\n[build]: https://github.com/wooorm/array-iterate/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/array-iterate.svg\n\n[coverage]: https://codecov.io/github/wooorm/array-iterate\n\n[downloads-badge]: https://img.shields.io/npm/dm/array-iterate.svg\n\n[downloads]: https://www.npmjs.com/package/array-iterate\n\n[size-badge]: https://img.shields.io/bundlephobia/minzip/array-iterate.svg\n\n[size]: https://bundlephobia.com/result?p=array-iterate\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esmsh]: https://esm.sh\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[typescript]: https://www.typescriptlang.org\n\n[contribute]: https://opensource.guide/how-to-contribute/\n\n[foreach]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Farray-iterate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwooorm%2Farray-iterate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Farray-iterate/lists"}