1 | # each-arg
|
2 |
|
3 | Iterates through arguments or any other array-like object starting from specific index.
|
4 |
|
5 | ## Install
|
6 |
|
7 | ```bach
|
8 | npm i each-arg
|
9 | ```
|
10 |
|
11 | ## Usage
|
12 |
|
13 | ##### syntax
|
14 |
|
15 | ```typescript
|
16 | eachArg(arr, start, callback(value, index, ...extra): any, ...extra): void;
|
17 | ```
|
18 |
|
19 | Iterates over the `array` 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.
|
20 |
|
21 | Any `extra` argument passed to `eachArg` function will be passed down to the `callback` function.
|
22 |
|
23 | 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.
|
24 |
|
25 | ```typescript
|
26 | eachArg.call(thisArg, arr, start, callback, ..extra);
|
27 | ```
|
28 |
|
29 | ##### example
|
30 |
|
31 | ```javascript
|
32 | import eachArg from "each-arg";
|
33 |
|
34 | eachArg([1, 2, 3, 4, 5], 1, (value, index, num) => {
|
35 | console.log(value + " >> " + (index + num));
|
36 | return index === 3;
|
37 | }, 100);
|
38 | ```
|
39 |
|
40 | ```console
|
41 | 2 >> 101
|
42 | 3 >> 102
|
43 | 4 >> 103
|
44 | ```
|
45 |
|
46 | ## License
|
47 |
|
48 | [MIT](LICENSE) © [Manuel Fernández](https://github.com/manferlo81)
|