# @writetome51/array-get-indexes-of

> Functions that return indexes of items in an array. Optional arguments give you more flexibility than Array.prototype.indexOf()

Latest version **3.0.2** (published 2021-11-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @writetome51/array-get-indexes-of
pnpm add @writetome51/array-get-indexes-of
yarn add @writetome51/array-get-indexes-of
bun add @writetome51/array-get-indexes-of
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2021-11-06 |
| First published | 2020-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Steve Thompson |
| Maintainers | writetome51 |
| Keywords | array, search, get, find, index, index-of, indexes, data |

## Links

- npm: https://www.npmjs.com/package/@writetome51/array-get-indexes-of
- Repository: https://github.com/writetome51/array-get-indexes-of
- Homepage: https://github.com/writetome51/array-get-indexes-of#readme
- Issues: https://github.com/writetome51/array-get-indexes-of/issues
- npm.io page: https://npm.io/package/@writetome51/array-get-indexes-of

## Dependencies (5)

- [error-if-not-array](https://npm.io/package/error-if-not-array.md) >=2.0.0
- [error-if-not-integer](https://npm.io/package/error-if-not-integer.md) >=2.0.1
- [@writetome51/is-match](https://npm.io/package/@writetome51/is-match.md) >=0.0.1
- [@writetome51/is-array-not-array](https://npm.io/package/@writetome51/is-array-not-array.md) >=2.0.0
- [@writetome51/array-append-prepend](https://npm.io/package/@writetome51/array-append-prepend.md) >=3.0.0

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 3.0.2 (latest) — 2021-11-06
- 3.0.1 — 2021-04-08
- 3.0.0 — 2021-03-12
- 2.0.2 — 2020-09-08
- 2.0.1 — 2020-08-12
- 2.0.0 — 2020-07-31

## README

# getIndexOf(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value, array, whichInstance? = 1<br>): number

Returns index of `value` found in `array`. Returns -1 if `value` isn't found. Optional  
`whichInstance` specifies which instance of `value` to search for. By default it's the  
first instance. You can set it to a negative number to search from the end.


# getIndexesOf(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;howMany? = array.length<br>): number[]

Returns indexes of `value` in `array`.  If you don't need every index, set `howMany` to  
desired number to speed up execution.  You can set `howMany` to negative number to  
search from the end (i.e., `-2` gets the last 2 indexes of `value`).


## How an Array is found
If `value` is Array, identical matching via `===` is tried first. If there's no match,  
`value` is searched for using this algorithm:  
For each `i` in `array`:  &nbsp; if `array[i]` is Array, each item inside `array[i]` is  
checked to see if it matches the item with the same index in `value`, using the `===`  
operator.  If those two items are both Arrays, the same algorithm is recursively run on  
them.


## Examples
```js
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10];

getIndexOf(100, arr);
// -->  -1

getIndexOf(10, arr);
// -->  9

// If 'whichInstance' is greater than num indexes available, the last available 
// index is returned.
getIndexOf(10, arr, 4);
// -->  11

// The better way to get the last index:
getIndexOf(10, arr, -1);
// -->  11

getIndexOf(10, arr, -3);
// -->  9

arr = [1, 'h', [3], 1, 'h', [3], 1, 'h', [3], 1, 'h', [3], 1];

getIndexesOf(100, arr);
// -->  []

getIndexesOf(1, arr);
// -->  [0, 3, 6, 9, 12]

// If 'howMany' is greater than num indexes available, it returns all
// indexes available:
getIndexesOf(1, arr, 8);
// -->  [0, 3, 6, 9, 12]

getIndexesOf([3], arr, 2);
// -->  [2, 5]

getIndexesOf([3], arr, -3);
// -->  [5, 8, 11]
```


## Installation
`npm i  @writetome51/array-get-indexes-of`


## Loading
```js
import {getIndexOf, getIndexesOf} from '@writetome51/array-get-indexes-of'
```

---
_Source: https://npm.io/package/@writetome51/array-get-indexes-of · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
