https://github.com/manferlo81/each-arg
Iterates through arguments or any other array-like object starting from specific index.
https://github.com/manferlo81/each-arg
arguments array array-like callback each for-each params
Last synced: 10 months ago
JSON representation
Iterates through arguments or any other array-like object starting from specific index.
- Host: GitHub
- URL: https://github.com/manferlo81/each-arg
- Owner: manferlo81
- License: mit
- Created: 2019-06-01T09:06:49.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-02-08T10:01:59.000Z (11 months ago)
- Last Synced: 2025-02-08T11:18:31.301Z (11 months ago)
- Topics: arguments, array, array-like, callback, each, for-each, params
- Language: TypeScript
- Size: 2.29 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# each-arg
[](https://circleci.com/gh/manferlo81/each-arg)
[](https://www.npmjs.com/package/each-arg)
[](https://codecov.io/gh/manferlo81/each-arg)
[](https://www.jsdelivr.com/package/npm/each-arg)
[](https://packagephobia.now.sh/result?p=each-arg)
[](https://bundlephobia.com/result?p=each-arg)
[](https://github.com/microsoft/typescript)
[](https://snyk.io/test/github/manferlo81/each-arg?targetFile=package.json)
[](LICENSE)
Iterates through arguments or any other array-like object starting from a specific index.
## Install
```bach
npm i each-arg
```
## CDN
### jsDelivr
```html
```
*for production...*
```html
<script src="https://cdn.jsdelivr.net/npm/each-arg@latest/dist/umd/each-arg.umd.min.js">
```
[more options...](https://www.jsdelivr.com/package/npm/each-arg?version=latest)
### unpkg
```html
<script src="https://unpkg.com/each-arg@latest/dist/umd/each-arg.umd.js">
```
*for production...*
```html
<script src="https://unpkg.com/each-arg@latest/dist/umd/each-arg.umd.min.js">
```
[more options...](https://unpkg.com/each-arg@latest/)
## Reference
***syntax***
```typescript
eachArg(arr, start, callback(value, index, ...extra): any, ...extra): void;
```
*Iterates over the* `array`*,* `string` *or* `array-like` `arr` *starting from the* `start` *index. The* `callback` *function will be called for every* `value` *in the array, with the* `value` *itself, the* `index` *of the current item and any* `extra` *argument passed to* `eachArg` *function.*
*If a negative* `start` *index is provided the iteration will start from* `X` *number of items counting from the last item in the input array-like.*
*If the* `callback` *returns a truthy value the iteration will stop.*
*Any* `extra` *argument passed to* `eachArg` *function will be passed down to the* `callback` *function.*
*The* `callback` *function inherits the* `this` *value form the* `eachArg` *function call. If you need a specific value inside the* `callback`, *call* `eachArg` *using it's* `call` *method.*
```typescript
eachArg.call(thisArg, arr, start, callback, ..extra);
```
***example***
```javascript
import eachArg from "each-arg";
eachArg([1, 2, 3, 4, 5], 1, (value, index, num) => {
console.log(value + " >> " + (index + num));
return index === 3;
}, 100);
```
```console
2 >> 101
3 >> 102
4 >> 103
```
## Usage
### Node.js
```javascript
const eachArg = require("each-arg");
eachArg(args, start, callback);
```
### Browser
*After adding the* `script` *tag,* `eachArg` *function will be available globally through* `eachArg` *or* `window.eachArg`*.*
```javascript
eachArg(args, start, callback);
```
## License
[MIT](LICENSE) © [Manuel Fernández](https://github.com/manferlo81)